{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.patches as mpatches\n",
    "import numpy as np\n",
    "import re\n",
    "import calendar\n",
    "import os"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Make dictionary of suggested colors for reanalysis comparison"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "metadata": {},
   "outputs": [],
   "source": [
    "dummy = \"\"\"r,g,b,c,m,y,k,RGB Hexadecimal,reanalysis\n",
    "    226, 31, 38,  0,86.28,83.19,11.37,  E21F26,  MERRA2\n",
    "    246, 153, 153,  0,37.8,37.8,3.53,  F69999,  MERRA\n",
    "    41, 95, 138,  70.29,31.16,0,45.88,  295F8A,  ERAI\n",
    "    95, 152, 198,  52.02,23.23,0,22.35,  5F98C6,  ERA5\n",
    "    175, 203, 227,  22.91,10.57,0,10.98,  AFCBE3,  ERA40\n",
    "    114, 59, 122,  6.56,51.64,0,52.16,  723B7A,  JRA55\n",
    "    173, 113, 181,  4.42,37.57,0,29.02,  AD71B5,  JRA-55C or JRA-55 AMIP\n",
    "    214, 184, 218,  1.83,15.6,0,14.51,  D6B8DA,  JRA-25\n",
    "    245, 126, 32,  0,48.57,86.94,3.92,  F57E20,  NCEP-R1\n",
    "    253, 191, 110,  0,24.51,56.52,0.78,  FDBF6E,  NCEP-R2\n",
    "    236, 0, 140,  0,100,40.68,7.45,  EC008C,  20CRv2c\n",
    "    247, 153, 209,  0,38.06,15.38,3.14,  F799D1,  20CRv2\n",
    "    0, 174, 239,  100,27.2,0,6.27,  00AEEF,  CERA-20C\n",
    "    96, 200, 232,  58.62,13.79,0,9.02,  60C8E8,  ERA-20C\n",
    "    52, 160, 72,  67.5,0,55,37.25,  34A048,  CFSR\n",
    "    179, 91, 40,  0,49.16,77.65,29.8,  B35B28,  REM\n",
    "    255,215,0,  0,15.69,100,0,  FFD700,  Other\n",
    "    0, 0, 0,  0,0,0,100,  000000,  Obs\n",
    "    119, 119, 119,  0,0,0,53.33,  777777,  Other Obs\"\"\"\n",
    "\n",
    "reanalysis_color = {}\n",
    "for line in dummy.split('\\n')[1:]:\n",
    "    v, k = line.split(',')[-2:]\n",
    "    reanalysis_color[k.strip()] = '#'+v.strip()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Lat</th>\n",
       "      <th>Lon</th>\n",
       "      <th>NP</th>\n",
       "      <th>Pg</th>\n",
       "      <th>Pc</th>\n",
       "      <th>ERAI_prectot</th>\n",
       "      <th>CFSR_prectot</th>\n",
       "      <th>MERRA_prectot</th>\n",
       "      <th>MERRA2_prectot</th>\n",
       "      <th>JRA55_prectot</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>1980-01-01</td>\n",
       "      <td>77.651090</td>\n",
       "      <td>156.965000</td>\n",
       "      <td>22.0</td>\n",
       "      <td>11.1</td>\n",
       "      <td>20.8</td>\n",
       "      <td>16.181337</td>\n",
       "      <td>17.735622</td>\n",
       "      <td>17.998478</td>\n",
       "      <td>20.466927</td>\n",
       "      <td>16.106415</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>1980-02-01</td>\n",
       "      <td>77.895357</td>\n",
       "      <td>153.956488</td>\n",
       "      <td>22.0</td>\n",
       "      <td>5.5</td>\n",
       "      <td>9.7</td>\n",
       "      <td>7.366097</td>\n",
       "      <td>8.458306</td>\n",
       "      <td>7.518522</td>\n",
       "      <td>11.490108</td>\n",
       "      <td>7.683252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>1980-03-01</td>\n",
       "      <td>78.249753</td>\n",
       "      <td>153.594198</td>\n",
       "      <td>22.0</td>\n",
       "      <td>6.8</td>\n",
       "      <td>13.3</td>\n",
       "      <td>9.585857</td>\n",
       "      <td>11.132812</td>\n",
       "      <td>8.174619</td>\n",
       "      <td>13.588425</td>\n",
       "      <td>8.141494</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>1980-04-01</td>\n",
       "      <td>78.580778</td>\n",
       "      <td>151.989833</td>\n",
       "      <td>22.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.7</td>\n",
       "      <td>2.645907</td>\n",
       "      <td>3.820143</td>\n",
       "      <td>7.373949</td>\n",
       "      <td>7.497791</td>\n",
       "      <td>2.491471</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>1980-05-01</td>\n",
       "      <td>79.146167</td>\n",
       "      <td>147.978611</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>4.8</td>\n",
       "      <td>8.435853</td>\n",
       "      <td>13.876427</td>\n",
       "      <td>17.613360</td>\n",
       "      <td>11.865479</td>\n",
       "      <td>12.269393</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Date        Lat         Lon    NP    Pg    Pc  ERAI_prectot  \\\n",
       "69 1980-01-01  77.651090  156.965000  22.0  11.1  20.8     16.181337   \n",
       "70 1980-02-01  77.895357  153.956488  22.0   5.5   9.7      7.366097   \n",
       "71 1980-03-01  78.249753  153.594198  22.0   6.8  13.3      9.585857   \n",
       "72 1980-04-01  78.580778  151.989833  22.0   2.0   5.7      2.645907   \n",
       "73 1980-05-01  79.146167  147.978611  22.0   1.4   4.8      8.435853   \n",
       "\n",
       "    CFSR_prectot  MERRA_prectot  MERRA2_prectot  JRA55_prectot  \n",
       "69     17.735622      17.998478       20.466927      16.106415  \n",
       "70      8.458306       7.518522       11.490108       7.683252  \n",
       "71     11.132812       8.174619       13.588425       8.141494  \n",
       "72      3.820143       7.373949        7.497791       2.491471  \n",
       "73     13.876427      17.613360       11.865479      12.269393  "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "filepath = r'C:\\Users\\apbarret\\Documents\\data\\Arctic_precip\\np_reanalysis_month_comparison.csv'\n",
    "df = pd.read_csv(filepath, index_col=0, parse_dates=['Date'])\n",
    "df = df.dropna()\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculate bias as P_reanalysis/P_obs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Lat</th>\n",
       "      <th>Lon</th>\n",
       "      <th>NP</th>\n",
       "      <th>Pg</th>\n",
       "      <th>Pc</th>\n",
       "      <th>ERAI_prectot</th>\n",
       "      <th>CFSR_prectot</th>\n",
       "      <th>MERRA_prectot</th>\n",
       "      <th>MERRA2_prectot</th>\n",
       "      <th>JRA55_prectot</th>\n",
       "      <th>ERAI_bias</th>\n",
       "      <th>CFSR_bias</th>\n",
       "      <th>MERRA_bias</th>\n",
       "      <th>MERRA2_bias</th>\n",
       "      <th>JRA55_bias</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>1980-01-01</td>\n",
       "      <td>77.651090</td>\n",
       "      <td>156.965000</td>\n",
       "      <td>22.0</td>\n",
       "      <td>11.1</td>\n",
       "      <td>20.8</td>\n",
       "      <td>16.181337</td>\n",
       "      <td>17.735622</td>\n",
       "      <td>17.998478</td>\n",
       "      <td>20.466927</td>\n",
       "      <td>16.106415</td>\n",
       "      <td>77.794889</td>\n",
       "      <td>85.267413</td>\n",
       "      <td>86.531144</td>\n",
       "      <td>98.398687</td>\n",
       "      <td>77.434687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>1980-02-01</td>\n",
       "      <td>77.895357</td>\n",
       "      <td>153.956488</td>\n",
       "      <td>22.0</td>\n",
       "      <td>5.5</td>\n",
       "      <td>9.7</td>\n",
       "      <td>7.366097</td>\n",
       "      <td>8.458306</td>\n",
       "      <td>7.518522</td>\n",
       "      <td>11.490108</td>\n",
       "      <td>7.683252</td>\n",
       "      <td>75.939144</td>\n",
       "      <td>87.199031</td>\n",
       "      <td>77.510536</td>\n",
       "      <td>118.454727</td>\n",
       "      <td>79.208787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>1980-03-01</td>\n",
       "      <td>78.249753</td>\n",
       "      <td>153.594198</td>\n",
       "      <td>22.0</td>\n",
       "      <td>6.8</td>\n",
       "      <td>13.3</td>\n",
       "      <td>9.585857</td>\n",
       "      <td>11.132812</td>\n",
       "      <td>8.174619</td>\n",
       "      <td>13.588425</td>\n",
       "      <td>8.141494</td>\n",
       "      <td>72.074113</td>\n",
       "      <td>83.705353</td>\n",
       "      <td>61.463301</td>\n",
       "      <td>102.168609</td>\n",
       "      <td>61.214241</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>1980-04-01</td>\n",
       "      <td>78.580778</td>\n",
       "      <td>151.989833</td>\n",
       "      <td>22.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.7</td>\n",
       "      <td>2.645907</td>\n",
       "      <td>3.820143</td>\n",
       "      <td>7.373949</td>\n",
       "      <td>7.497791</td>\n",
       "      <td>2.491471</td>\n",
       "      <td>46.419428</td>\n",
       "      <td>67.020053</td>\n",
       "      <td>129.367535</td>\n",
       "      <td>131.540198</td>\n",
       "      <td>43.710023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>1980-05-01</td>\n",
       "      <td>79.146167</td>\n",
       "      <td>147.978611</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1.4</td>\n",
       "      <td>4.8</td>\n",
       "      <td>8.435853</td>\n",
       "      <td>13.876427</td>\n",
       "      <td>17.613360</td>\n",
       "      <td>11.865479</td>\n",
       "      <td>12.269393</td>\n",
       "      <td>175.746938</td>\n",
       "      <td>289.092229</td>\n",
       "      <td>366.945000</td>\n",
       "      <td>247.197469</td>\n",
       "      <td>255.612354</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Date        Lat         Lon    NP    Pg    Pc  ERAI_prectot  \\\n",
       "69 1980-01-01  77.651090  156.965000  22.0  11.1  20.8     16.181337   \n",
       "70 1980-02-01  77.895357  153.956488  22.0   5.5   9.7      7.366097   \n",
       "71 1980-03-01  78.249753  153.594198  22.0   6.8  13.3      9.585857   \n",
       "72 1980-04-01  78.580778  151.989833  22.0   2.0   5.7      2.645907   \n",
       "73 1980-05-01  79.146167  147.978611  22.0   1.4   4.8      8.435853   \n",
       "\n",
       "    CFSR_prectot  MERRA_prectot  MERRA2_prectot  JRA55_prectot   ERAI_bias  \\\n",
       "69     17.735622      17.998478       20.466927      16.106415   77.794889   \n",
       "70      8.458306       7.518522       11.490108       7.683252   75.939144   \n",
       "71     11.132812       8.174619       13.588425       8.141494   72.074113   \n",
       "72      3.820143       7.373949        7.497791       2.491471   46.419428   \n",
       "73     13.876427      17.613360       11.865479      12.269393  175.746938   \n",
       "\n",
       "     CFSR_bias  MERRA_bias  MERRA2_bias  JRA55_bias  \n",
       "69   85.267413   86.531144    98.398687   77.434687  \n",
       "70   87.199031   77.510536   118.454727   79.208787  \n",
       "71   83.705353   61.463301   102.168609   61.214241  \n",
       "72   67.020053  129.367535   131.540198   43.710023  \n",
       "73  289.092229  366.945000   247.197469  255.612354  "
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p = re.compile('_prectot')\n",
    "#these_columns = [col for col in df.columns if p.search(col)]\n",
    "for col in df.columns:\n",
    "    if p.search(col):\n",
    "       df[col.replace('_prectot', '_bias')] = df[col]*100./df['Pc']\n",
    "       #df[col.replace('_prectot', '_bias')].where(df[col.replace('_prectot', '_bias')] > 0., inplace=True)\n",
    "    \n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ERAI_bias      13.624942\n",
       "MERRA_bias     13.690263\n",
       "MERRA2_bias    21.150981\n",
       "JRA55_bias     13.725106\n",
       "CFSR_bias      14.246598\n",
       "dtype: float64"
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.where(df > 0.)\n",
    "df[['ERAI_bias', 'MERRA_bias', 'MERRA2_bias', 'JRA55_bias', 'CFSR_bias']].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "75      84.262775\n",
       "87      57.414465\n",
       "121    131.101165\n",
       "126    136.854957\n",
       "138    164.923656\n",
       "150     95.929977\n",
       "159           NaN\n",
       "171     81.186576\n",
       "178    177.498567\n",
       "182     74.782951\n",
       "201    161.169690\n",
       "213    124.263167\n",
       "225    109.757470\n",
       "239     65.478526\n",
       "251    167.800675\n",
       "Name: MERRA_bias, dtype: float64"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.Date.dt.month == 7]['MERRA_bias']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [],
   "source": [
    "def setBoxColors(bp):\n",
    "    \n",
    "    reanalyses = ['ERAI', 'MERRA', 'MERRA2', 'JRA55', 'CFSR']\n",
    "\n",
    "    for r, box in zip(reanalyses,bp['boxes']):\n",
    "        # change outline color\n",
    "        box.set( color=reanalysis_color[r], linewidth=1)\n",
    "        \n",
    "    for r, whisker0, whisker1 in zip(reanalyses, bp['whiskers'][0::2], bp['whiskers'][1::2]):\n",
    "        whisker0.set(color=reanalysis_color[r], linewidth=2)\n",
    "        whisker1.set(color=reanalysis_color[r], linewidth=2)\n",
    "\n",
    "    for r, cap0, cap1 in zip(reanalyses, bp['caps'][0::2], bp['caps'][1::2]):\n",
    "        cap0.set(color=reanalysis_color[r], linewidth=2)\n",
    "        cap1.set(color=reanalysis_color[r], linewidth=2)\n",
    "        \n",
    "    for r, flier in zip(reanalyses, bp['fliers']):\n",
    "        flier.set(marker='o', markeredgecolor=reanalysis_color[r], markersize=3)\n",
    "    \n",
    "    for median in bp['medians']:\n",
    "        median.set(color='k', linewidth=2)\n",
    "        \n",
    "    return\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 304,
   "metadata": {},
   "outputs": [],
   "source": [
    "def columns2list(df, column=None):\n",
    "    if not column:\n",
    "        column = ['ERAI_bias', 'MERRA_bias', 'MERRA2_bias', 'JRA55_bias', 'CFSR_bias']\n",
    "    print (column)\n",
    "    result = []\n",
    "    for c in column:\n",
    "        x = df[c].values\n",
    "        result.append(x[~np.isnan(x)])\n",
    "        \n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to  previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overriden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"999.4166666666666\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize=(10,8))\n",
    "\n",
    "column = ['ERAI_bias', 'MERRA_bias', 'MERRA2_bias', 'JRA55_bias', 'CFSR_bias']\n",
    "labels = [c.replace('_bias','') for c in column]\n",
    "\n",
    "for month in range(1,13):\n",
    "    pos = [month+p for p in [-0.3,-0.15,0.,0.15,0.3]]\n",
    "    #x = [df[df['Date'].dt.month == month][c].values for c in column]\n",
    "    x = columns2list(df[df['Date'].dt.month == month])\n",
    "    bp = ax.boxplot(x, positions=pos, widths=0.1, labels=None, patch_artist=True)\n",
    "    setBoxColors(bp)\n",
    "\n",
    "ax.set_ylim(-10.,600.)\n",
    "ax.set_xlim(0,13)\n",
    "\n",
    "# Hide all but left y-axis\n",
    "ax.spines['top'].set_visible(False)\n",
    "ax.spines['bottom'].set_visible(False)\n",
    "ax.spines['right'].set_visible(False)\n",
    "#ax.set_xticks([])\n",
    "\n",
    "# Format left y-axis\n",
    "ax.set_ylabel('Bias %', fontsize=20)\n",
    "ax.axhline(100., linestyle='--', color='k')\n",
    "\n",
    "ax.set_xticks(range(1,13))\n",
    "ax.set_xticklabels(calendar.month_abbr[1:])\n",
    "\n",
    "ax.tick_params(axis='both', which='major', labelsize=15)\n",
    "ax.tick_params(axis='x', length=0)\n",
    "\n",
    "# Create legend\n",
    "handles = [mpatches.Patch(color=reanalysis_color[r], label=r) for r in labels]\n",
    "ax.legend(handles=handles, fontsize=18, frameon=False)\n",
    "\n",
    "fig.savefig(os.path.join(r'C:\\Users\\apbarret\\Documents\\Presentations\\AGU2018','yang_trajectory_reanalysis_bias.png'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ERAI_bias</th>\n",
       "      <th>MERRA_bias</th>\n",
       "      <th>MERRA2_bias</th>\n",
       "      <th>JRA55_bias</th>\n",
       "      <th>CFSR_bias</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.598682</td>\n",
       "      <td>0.598629</td>\n",
       "      <td>0.972133</td>\n",
       "      <td>0.616981</td>\n",
       "      <td>0.794398</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.509124</td>\n",
       "      <td>0.593413</td>\n",
       "      <td>0.937163</td>\n",
       "      <td>0.578566</td>\n",
       "      <td>0.769493</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.583668</td>\n",
       "      <td>0.631064</td>\n",
       "      <td>1.093020</td>\n",
       "      <td>0.589136</td>\n",
       "      <td>0.703195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.638384</td>\n",
       "      <td>0.961349</td>\n",
       "      <td>1.472527</td>\n",
       "      <td>0.737319</td>\n",
       "      <td>0.919286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1.042881</td>\n",
       "      <td>1.518751</td>\n",
       "      <td>1.589659</td>\n",
       "      <td>1.375163</td>\n",
       "      <td>1.517447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2.225945</td>\n",
       "      <td>1.873000</td>\n",
       "      <td>2.070380</td>\n",
       "      <td>2.328631</td>\n",
       "      <td>3.141089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1.287624</td>\n",
       "      <td>1.035498</td>\n",
       "      <td>1.485570</td>\n",
       "      <td>1.466149</td>\n",
       "      <td>1.777564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1.275991</td>\n",
       "      <td>0.752328</td>\n",
       "      <td>1.385277</td>\n",
       "      <td>1.353181</td>\n",
       "      <td>1.664435</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1.017170</td>\n",
       "      <td>0.755828</td>\n",
       "      <td>1.127862</td>\n",
       "      <td>1.063655</td>\n",
       "      <td>1.374107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.882565</td>\n",
       "      <td>0.790696</td>\n",
       "      <td>1.375187</td>\n",
       "      <td>0.867964</td>\n",
       "      <td>1.297895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.700109</td>\n",
       "      <td>0.809402</td>\n",
       "      <td>1.530274</td>\n",
       "      <td>0.597152</td>\n",
       "      <td>1.250447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.606480</td>\n",
       "      <td>0.649248</td>\n",
       "      <td>1.167482</td>\n",
       "      <td>0.671464</td>\n",
       "      <td>0.760334</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ERAI_bias  MERRA_bias  MERRA2_bias  JRA55_bias  CFSR_bias\n",
       "Date                                                           \n",
       "1      0.598682    0.598629     0.972133    0.616981   0.794398\n",
       "2      0.509124    0.593413     0.937163    0.578566   0.769493\n",
       "3      0.583668    0.631064     1.093020    0.589136   0.703195\n",
       "4      0.638384    0.961349     1.472527    0.737319   0.919286\n",
       "5      1.042881    1.518751     1.589659    1.375163   1.517447\n",
       "6      2.225945    1.873000     2.070380    2.328631   3.141089\n",
       "7      1.287624    1.035498     1.485570    1.466149   1.777564\n",
       "8      1.275991    0.752328     1.385277    1.353181   1.664435\n",
       "9      1.017170    0.755828     1.127862    1.063655   1.374107\n",
       "10     0.882565    0.790696     1.375187    0.867964   1.297895\n",
       "11     0.700109    0.809402     1.530274    0.597152   1.250447\n",
       "12     0.606480    0.649248     1.167482    0.671464   0.760334"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def sampleMean(x):\n",
    "    return x.sample(10, axis=0).mean(axis=0)*0.01\n",
    "\n",
    "columns = ['ERAI_bias','MERRA_bias','MERRA2_bias','JRA55_bias','CFSR_bias']\n",
    "df[columns].groupby(df.Date.dt.month).apply(sampleMean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 323,
   "metadata": {},
   "outputs": [],
   "source": [
    "train, test = train_test_split(df, test_size=0.33)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 324,
   "metadata": {},
   "outputs": [],
   "source": [
    "correction = train[columns].groupby(train.Date.dt.month).mean()*0.01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 325,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ERAI_bias      0.645975\n",
       "MERRA_bias     0.651502\n",
       "MERRA2_bias    1.148398\n",
       "JRA55_bias     0.725324\n",
       "CFSR_bias      0.925625\n",
       "Name: 1, dtype: float64"
      ]
     },
     "execution_count": 325,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "correction.loc[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 326,
   "metadata": {},
   "outputs": [],
   "source": [
    "def doCorrect(x, correction):\n",
    "    columns = ['ERAI_prectot','MERRA_prectot','MERRA2_prectot','JRA55_prectot','CFSR_prectot']\n",
    "    month = x.Date.dt.month.values[0]\n",
    "    for c in columns:\n",
    "        x[c.replace('_prectot','_corr')] = x[c]/correction[c.replace('_prectot','_bias')].loc[month]\n",
    "        x[c.replace('_prectot','_corrbias')] = x[c.replace('_prectot','_corr')]*100./x['Pc']\n",
    "    return x\n",
    "    \n",
    "result = test.groupby(test.Date.dt.month).apply(doCorrect, correction)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 327,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Lat</th>\n",
       "      <th>Lon</th>\n",
       "      <th>NP</th>\n",
       "      <th>Pg</th>\n",
       "      <th>Pc</th>\n",
       "      <th>ERAI_prectot</th>\n",
       "      <th>CFSR_prectot</th>\n",
       "      <th>MERRA_prectot</th>\n",
       "      <th>MERRA2_prectot</th>\n",
       "      <th>...</th>\n",
       "      <th>ERAI_corr</th>\n",
       "      <th>ERAI_corrbias</th>\n",
       "      <th>MERRA_corr</th>\n",
       "      <th>MERRA_corrbias</th>\n",
       "      <th>MERRA2_corr</th>\n",
       "      <th>MERRA2_corrbias</th>\n",
       "      <th>JRA55_corr</th>\n",
       "      <th>JRA55_corrbias</th>\n",
       "      <th>CFSR_corr</th>\n",
       "      <th>CFSR_corrbias</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>229</th>\n",
       "      <td>1990-11-01</td>\n",
       "      <td>84.457278</td>\n",
       "      <td>237.647556</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>3.8</td>\n",
       "      <td>3.506223</td>\n",
       "      <td>5.752460</td>\n",
       "      <td>4.161959</td>\n",
       "      <td>9.600878</td>\n",
       "      <td>...</td>\n",
       "      <td>4.939336</td>\n",
       "      <td>129.982526</td>\n",
       "      <td>5.608552</td>\n",
       "      <td>147.593485</td>\n",
       "      <td>6.291006</td>\n",
       "      <td>165.552779</td>\n",
       "      <td>8.523328</td>\n",
       "      <td>224.298095</td>\n",
       "      <td>4.769838</td>\n",
       "      <td>125.522047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>134</th>\n",
       "      <td>1982-03-01</td>\n",
       "      <td>81.284368</td>\n",
       "      <td>164.895977</td>\n",
       "      <td>25.0</td>\n",
       "      <td>3.9</td>\n",
       "      <td>9.4</td>\n",
       "      <td>5.428150</td>\n",
       "      <td>8.311910</td>\n",
       "      <td>7.141147</td>\n",
       "      <td>12.375418</td>\n",
       "      <td>...</td>\n",
       "      <td>8.842732</td>\n",
       "      <td>94.071614</td>\n",
       "      <td>11.311585</td>\n",
       "      <td>120.336008</td>\n",
       "      <td>11.191613</td>\n",
       "      <td>119.059718</td>\n",
       "      <td>10.321974</td>\n",
       "      <td>109.808234</td>\n",
       "      <td>12.242347</td>\n",
       "      <td>130.237737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>1983-10-01</td>\n",
       "      <td>85.728596</td>\n",
       "      <td>219.265526</td>\n",
       "      <td>25.0</td>\n",
       "      <td>16.6</td>\n",
       "      <td>32.5</td>\n",
       "      <td>22.214882</td>\n",
       "      <td>25.417803</td>\n",
       "      <td>17.650217</td>\n",
       "      <td>34.470240</td>\n",
       "      <td>...</td>\n",
       "      <td>25.175504</td>\n",
       "      <td>77.463089</td>\n",
       "      <td>21.769941</td>\n",
       "      <td>66.984434</td>\n",
       "      <td>23.955548</td>\n",
       "      <td>73.709378</td>\n",
       "      <td>25.998124</td>\n",
       "      <td>79.994227</td>\n",
       "      <td>18.873185</td>\n",
       "      <td>58.071339</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>195</th>\n",
       "      <td>1988-01-01</td>\n",
       "      <td>74.456500</td>\n",
       "      <td>175.716611</td>\n",
       "      <td>30.0</td>\n",
       "      <td>8.3</td>\n",
       "      <td>15.9</td>\n",
       "      <td>19.281849</td>\n",
       "      <td>20.696077</td>\n",
       "      <td>22.736380</td>\n",
       "      <td>23.766132</td>\n",
       "      <td>...</td>\n",
       "      <td>29.849207</td>\n",
       "      <td>187.730861</td>\n",
       "      <td>34.898430</td>\n",
       "      <td>219.486981</td>\n",
       "      <td>20.695022</td>\n",
       "      <td>130.157370</td>\n",
       "      <td>24.521549</td>\n",
       "      <td>154.223578</td>\n",
       "      <td>22.359028</td>\n",
       "      <td>140.622814</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>187</th>\n",
       "      <td>1987-12-01</td>\n",
       "      <td>83.113441</td>\n",
       "      <td>112.734086</td>\n",
       "      <td>29.0</td>\n",
       "      <td>4.7</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.180763</td>\n",
       "      <td>8.082131</td>\n",
       "      <td>5.089871</td>\n",
       "      <td>6.526690</td>\n",
       "      <td>...</td>\n",
       "      <td>8.242759</td>\n",
       "      <td>82.427586</td>\n",
       "      <td>7.821765</td>\n",
       "      <td>78.217649</td>\n",
       "      <td>5.558932</td>\n",
       "      <td>55.589315</td>\n",
       "      <td>8.874286</td>\n",
       "      <td>88.742862</td>\n",
       "      <td>9.953389</td>\n",
       "      <td>99.533887</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>126</th>\n",
       "      <td>1981-07-01</td>\n",
       "      <td>76.587971</td>\n",
       "      <td>165.737754</td>\n",
       "      <td>25.0</td>\n",
       "      <td>18.1</td>\n",
       "      <td>23.2</td>\n",
       "      <td>46.557137</td>\n",
       "      <td>55.927620</td>\n",
       "      <td>31.750350</td>\n",
       "      <td>50.764930</td>\n",
       "      <td>...</td>\n",
       "      <td>33.317800</td>\n",
       "      <td>143.611207</td>\n",
       "      <td>25.728771</td>\n",
       "      <td>110.899876</td>\n",
       "      <td>31.588840</td>\n",
       "      <td>136.158791</td>\n",
       "      <td>37.814455</td>\n",
       "      <td>162.993341</td>\n",
       "      <td>28.053389</td>\n",
       "      <td>120.919778</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>1981-07-01</td>\n",
       "      <td>87.805484</td>\n",
       "      <td>123.403387</td>\n",
       "      <td>22.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>38.7</td>\n",
       "      <td>43.884410</td>\n",
       "      <td>46.174370</td>\n",
       "      <td>22.219398</td>\n",
       "      <td>38.982533</td>\n",
       "      <td>...</td>\n",
       "      <td>31.405110</td>\n",
       "      <td>81.150154</td>\n",
       "      <td>18.005402</td>\n",
       "      <td>46.525586</td>\n",
       "      <td>24.257159</td>\n",
       "      <td>62.679997</td>\n",
       "      <td>27.104950</td>\n",
       "      <td>70.038630</td>\n",
       "      <td>23.161142</td>\n",
       "      <td>59.847912</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>171</th>\n",
       "      <td>1984-07-01</td>\n",
       "      <td>81.722903</td>\n",
       "      <td>179.310430</td>\n",
       "      <td>26.0</td>\n",
       "      <td>33.0</td>\n",
       "      <td>42.5</td>\n",
       "      <td>53.239445</td>\n",
       "      <td>53.905410</td>\n",
       "      <td>34.504295</td>\n",
       "      <td>50.333122</td>\n",
       "      <td>...</td>\n",
       "      <td>38.099877</td>\n",
       "      <td>89.646769</td>\n",
       "      <td>27.960420</td>\n",
       "      <td>65.789223</td>\n",
       "      <td>31.320144</td>\n",
       "      <td>73.694456</td>\n",
       "      <td>34.681468</td>\n",
       "      <td>81.603454</td>\n",
       "      <td>27.039045</td>\n",
       "      <td>63.621282</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>218</th>\n",
       "      <td>1989-12-01</td>\n",
       "      <td>83.269355</td>\n",
       "      <td>204.633871</td>\n",
       "      <td>30.0</td>\n",
       "      <td>9.9</td>\n",
       "      <td>17.6</td>\n",
       "      <td>6.838073</td>\n",
       "      <td>6.979196</td>\n",
       "      <td>8.603964</td>\n",
       "      <td>12.784246</td>\n",
       "      <td>...</td>\n",
       "      <td>10.879592</td>\n",
       "      <td>61.815861</td>\n",
       "      <td>13.221981</td>\n",
       "      <td>75.124893</td>\n",
       "      <td>10.888635</td>\n",
       "      <td>61.867242</td>\n",
       "      <td>9.143457</td>\n",
       "      <td>51.951460</td>\n",
       "      <td>8.595092</td>\n",
       "      <td>48.835747</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248</th>\n",
       "      <td>1990-04-01</td>\n",
       "      <td>76.251389</td>\n",
       "      <td>225.536778</td>\n",
       "      <td>31.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>6.1</td>\n",
       "      <td>8.250469</td>\n",
       "      <td>10.761417</td>\n",
       "      <td>12.667414</td>\n",
       "      <td>13.151982</td>\n",
       "      <td>...</td>\n",
       "      <td>12.806466</td>\n",
       "      <td>209.942060</td>\n",
       "      <td>13.760322</td>\n",
       "      <td>225.579052</td>\n",
       "      <td>9.257512</td>\n",
       "      <td>151.762495</td>\n",
       "      <td>14.543996</td>\n",
       "      <td>238.426172</td>\n",
       "      <td>11.460344</td>\n",
       "      <td>187.874484</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>167</th>\n",
       "      <td>1984-03-01</td>\n",
       "      <td>80.028944</td>\n",
       "      <td>172.488778</td>\n",
       "      <td>26.0</td>\n",
       "      <td>5.6</td>\n",
       "      <td>12.0</td>\n",
       "      <td>6.120499</td>\n",
       "      <td>8.092849</td>\n",
       "      <td>7.564194</td>\n",
       "      <td>13.434068</td>\n",
       "      <td>...</td>\n",
       "      <td>9.970603</td>\n",
       "      <td>83.088358</td>\n",
       "      <td>11.981691</td>\n",
       "      <td>99.847426</td>\n",
       "      <td>12.148995</td>\n",
       "      <td>101.241628</td>\n",
       "      <td>12.572517</td>\n",
       "      <td>104.770972</td>\n",
       "      <td>11.919699</td>\n",
       "      <td>99.330828</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>200</th>\n",
       "      <td>1988-06-01</td>\n",
       "      <td>76.586605</td>\n",
       "      <td>161.910802</td>\n",
       "      <td>30.0</td>\n",
       "      <td>4.5</td>\n",
       "      <td>8.4</td>\n",
       "      <td>29.351267</td>\n",
       "      <td>28.456990</td>\n",
       "      <td>20.753227</td>\n",
       "      <td>21.182299</td>\n",
       "      <td>...</td>\n",
       "      <td>14.127225</td>\n",
       "      <td>168.181246</td>\n",
       "      <td>12.328179</td>\n",
       "      <td>146.764038</td>\n",
       "      <td>10.421743</td>\n",
       "      <td>124.068369</td>\n",
       "      <td>8.798284</td>\n",
       "      <td>104.741479</td>\n",
       "      <td>8.670894</td>\n",
       "      <td>103.224933</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182</th>\n",
       "      <td>1987-07-01</td>\n",
       "      <td>80.683925</td>\n",
       "      <td>111.693871</td>\n",
       "      <td>29.0</td>\n",
       "      <td>18.7</td>\n",
       "      <td>22.5</td>\n",
       "      <td>21.469885</td>\n",
       "      <td>29.468271</td>\n",
       "      <td>16.826164</td>\n",
       "      <td>34.436386</td>\n",
       "      <td>...</td>\n",
       "      <td>15.364547</td>\n",
       "      <td>68.286877</td>\n",
       "      <td>13.635016</td>\n",
       "      <td>60.600070</td>\n",
       "      <td>21.428287</td>\n",
       "      <td>95.236829</td>\n",
       "      <td>17.752427</td>\n",
       "      <td>78.899676</td>\n",
       "      <td>14.781334</td>\n",
       "      <td>65.694820</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>1984-10-01</td>\n",
       "      <td>81.896559</td>\n",
       "      <td>172.872097</td>\n",
       "      <td>26.0</td>\n",
       "      <td>13.2</td>\n",
       "      <td>20.1</td>\n",
       "      <td>20.865042</td>\n",
       "      <td>24.670158</td>\n",
       "      <td>14.383730</td>\n",
       "      <td>27.149641</td>\n",
       "      <td>...</td>\n",
       "      <td>23.645768</td>\n",
       "      <td>117.640637</td>\n",
       "      <td>17.741026</td>\n",
       "      <td>88.263810</td>\n",
       "      <td>18.868001</td>\n",
       "      <td>93.870652</td>\n",
       "      <td>17.400220</td>\n",
       "      <td>86.568257</td>\n",
       "      <td>18.318045</td>\n",
       "      <td>91.134552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>157</th>\n",
       "      <td>1984-02-01</td>\n",
       "      <td>85.633854</td>\n",
       "      <td>234.618438</td>\n",
       "      <td>25.0</td>\n",
       "      <td>11.3</td>\n",
       "      <td>19.5</td>\n",
       "      <td>6.212657</td>\n",
       "      <td>6.729545</td>\n",
       "      <td>5.126431</td>\n",
       "      <td>12.353541</td>\n",
       "      <td>...</td>\n",
       "      <td>9.208445</td>\n",
       "      <td>47.222792</td>\n",
       "      <td>6.743434</td>\n",
       "      <td>34.581712</td>\n",
       "      <td>10.306082</td>\n",
       "      <td>52.851702</td>\n",
       "      <td>8.872187</td>\n",
       "      <td>45.498395</td>\n",
       "      <td>7.149876</td>\n",
       "      <td>36.666029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>1989-02-01</td>\n",
       "      <td>77.481548</td>\n",
       "      <td>207.048214</td>\n",
       "      <td>31.0</td>\n",
       "      <td>21.3</td>\n",
       "      <td>42.4</td>\n",
       "      <td>32.025032</td>\n",
       "      <td>40.694126</td>\n",
       "      <td>18.994719</td>\n",
       "      <td>31.084469</td>\n",
       "      <td>...</td>\n",
       "      <td>47.467727</td>\n",
       "      <td>111.952186</td>\n",
       "      <td>24.986120</td>\n",
       "      <td>58.929527</td>\n",
       "      <td>25.932571</td>\n",
       "      <td>61.161725</td>\n",
       "      <td>45.106566</td>\n",
       "      <td>106.383410</td>\n",
       "      <td>43.235901</td>\n",
       "      <td>101.971464</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>220</th>\n",
       "      <td>1990-02-01</td>\n",
       "      <td>82.074405</td>\n",
       "      <td>209.070833</td>\n",
       "      <td>30.0</td>\n",
       "      <td>15.7</td>\n",
       "      <td>31.1</td>\n",
       "      <td>7.239990</td>\n",
       "      <td>10.467795</td>\n",
       "      <td>7.634984</td>\n",
       "      <td>10.972231</td>\n",
       "      <td>...</td>\n",
       "      <td>10.731164</td>\n",
       "      <td>34.505349</td>\n",
       "      <td>10.043245</td>\n",
       "      <td>32.293393</td>\n",
       "      <td>9.153708</td>\n",
       "      <td>29.433146</td>\n",
       "      <td>10.748734</td>\n",
       "      <td>34.561846</td>\n",
       "      <td>11.121618</td>\n",
       "      <td>35.760831</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>120</th>\n",
       "      <td>1980-06-01</td>\n",
       "      <td>88.506358</td>\n",
       "      <td>105.537901</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.7</td>\n",
       "      <td>12.9</td>\n",
       "      <td>27.898235</td>\n",
       "      <td>34.289886</td>\n",
       "      <td>17.831097</td>\n",
       "      <td>27.192526</td>\n",
       "      <td>...</td>\n",
       "      <td>13.427858</td>\n",
       "      <td>104.091919</td>\n",
       "      <td>10.592327</td>\n",
       "      <td>82.111059</td>\n",
       "      <td>13.378789</td>\n",
       "      <td>103.711546</td>\n",
       "      <td>12.211631</td>\n",
       "      <td>94.663805</td>\n",
       "      <td>10.448188</td>\n",
       "      <td>80.993705</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>259</th>\n",
       "      <td>1991-03-01</td>\n",
       "      <td>72.152151</td>\n",
       "      <td>211.378333</td>\n",
       "      <td>31.0</td>\n",
       "      <td>2.2</td>\n",
       "      <td>5.2</td>\n",
       "      <td>4.430024</td>\n",
       "      <td>5.285304</td>\n",
       "      <td>6.797879</td>\n",
       "      <td>9.095493</td>\n",
       "      <td>...</td>\n",
       "      <td>7.216734</td>\n",
       "      <td>138.783344</td>\n",
       "      <td>10.767847</td>\n",
       "      <td>207.073988</td>\n",
       "      <td>8.225439</td>\n",
       "      <td>158.181513</td>\n",
       "      <td>7.654339</td>\n",
       "      <td>147.198829</td>\n",
       "      <td>7.784557</td>\n",
       "      <td>149.703010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>249</th>\n",
       "      <td>1990-05-01</td>\n",
       "      <td>76.346237</td>\n",
       "      <td>226.064677</td>\n",
       "      <td>31.0</td>\n",
       "      <td>1.8</td>\n",
       "      <td>4.8</td>\n",
       "      <td>8.504047</td>\n",
       "      <td>20.605352</td>\n",
       "      <td>14.453971</td>\n",
       "      <td>16.353298</td>\n",
       "      <td>...</td>\n",
       "      <td>6.935304</td>\n",
       "      <td>144.485502</td>\n",
       "      <td>7.389307</td>\n",
       "      <td>153.943892</td>\n",
       "      <td>8.277537</td>\n",
       "      <td>172.448680</td>\n",
       "      <td>7.494069</td>\n",
       "      <td>156.126434</td>\n",
       "      <td>11.343597</td>\n",
       "      <td>236.324946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>1981-11-01</td>\n",
       "      <td>89.220000</td>\n",
       "      <td>126.638944</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.6</td>\n",
       "      <td>16.1</td>\n",
       "      <td>10.508002</td>\n",
       "      <td>12.805978</td>\n",
       "      <td>6.745749</td>\n",
       "      <td>17.167664</td>\n",
       "      <td>...</td>\n",
       "      <td>14.802979</td>\n",
       "      <td>91.943971</td>\n",
       "      <td>9.090404</td>\n",
       "      <td>56.462134</td>\n",
       "      <td>11.249166</td>\n",
       "      <td>69.870596</td>\n",
       "      <td>13.425398</td>\n",
       "      <td>83.387567</td>\n",
       "      <td>10.618491</td>\n",
       "      <td>65.953358</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>116</th>\n",
       "      <td>1980-02-01</td>\n",
       "      <td>86.399467</td>\n",
       "      <td>129.356400</td>\n",
       "      <td>24.0</td>\n",
       "      <td>10.1</td>\n",
       "      <td>22.3</td>\n",
       "      <td>6.253841</td>\n",
       "      <td>8.977540</td>\n",
       "      <td>5.399393</td>\n",
       "      <td>12.788603</td>\n",
       "      <td>...</td>\n",
       "      <td>9.269487</td>\n",
       "      <td>41.567206</td>\n",
       "      <td>7.102494</td>\n",
       "      <td>31.849747</td>\n",
       "      <td>10.669037</td>\n",
       "      <td>47.843216</td>\n",
       "      <td>8.855226</td>\n",
       "      <td>39.709531</td>\n",
       "      <td>9.538281</td>\n",
       "      <td>42.772563</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>1980-04-01</td>\n",
       "      <td>78.580778</td>\n",
       "      <td>151.989833</td>\n",
       "      <td>22.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>5.7</td>\n",
       "      <td>2.645907</td>\n",
       "      <td>3.820143</td>\n",
       "      <td>7.373949</td>\n",
       "      <td>7.497791</td>\n",
       "      <td>...</td>\n",
       "      <td>4.107006</td>\n",
       "      <td>72.052730</td>\n",
       "      <td>8.010153</td>\n",
       "      <td>140.528995</td>\n",
       "      <td>5.277600</td>\n",
       "      <td>92.589466</td>\n",
       "      <td>3.280588</td>\n",
       "      <td>57.554178</td>\n",
       "      <td>4.068252</td>\n",
       "      <td>71.372834</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>1990-02-01</td>\n",
       "      <td>76.306548</td>\n",
       "      <td>224.693452</td>\n",
       "      <td>31.0</td>\n",
       "      <td>5.9</td>\n",
       "      <td>13.9</td>\n",
       "      <td>4.747919</td>\n",
       "      <td>10.501060</td>\n",
       "      <td>4.231576</td>\n",
       "      <td>9.049299</td>\n",
       "      <td>...</td>\n",
       "      <td>7.037398</td>\n",
       "      <td>50.628764</td>\n",
       "      <td>5.566319</td>\n",
       "      <td>40.045460</td>\n",
       "      <td>7.549480</td>\n",
       "      <td>54.312809</td>\n",
       "      <td>7.066497</td>\n",
       "      <td>50.838109</td>\n",
       "      <td>11.156962</td>\n",
       "      <td>80.265912</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>256</th>\n",
       "      <td>1990-12-01</td>\n",
       "      <td>72.960000</td>\n",
       "      <td>214.974946</td>\n",
       "      <td>31.0</td>\n",
       "      <td>12.3</td>\n",
       "      <td>23.8</td>\n",
       "      <td>15.258500</td>\n",
       "      <td>19.664350</td>\n",
       "      <td>14.248206</td>\n",
       "      <td>18.816673</td>\n",
       "      <td>...</td>\n",
       "      <td>24.276758</td>\n",
       "      <td>102.003184</td>\n",
       "      <td>21.895665</td>\n",
       "      <td>91.998591</td>\n",
       "      <td>16.026591</td>\n",
       "      <td>67.338616</td>\n",
       "      <td>22.964679</td>\n",
       "      <td>96.490247</td>\n",
       "      <td>24.217242</td>\n",
       "      <td>101.753116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>232</th>\n",
       "      <td>1991-02-01</td>\n",
       "      <td>83.063210</td>\n",
       "      <td>235.833395</td>\n",
       "      <td>30.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>4.2</td>\n",
       "      <td>2.484306</td>\n",
       "      <td>4.924433</td>\n",
       "      <td>4.206443</td>\n",
       "      <td>7.601359</td>\n",
       "      <td>...</td>\n",
       "      <td>3.682256</td>\n",
       "      <td>87.672767</td>\n",
       "      <td>5.533259</td>\n",
       "      <td>131.744256</td>\n",
       "      <td>6.341520</td>\n",
       "      <td>150.988573</td>\n",
       "      <td>7.277026</td>\n",
       "      <td>173.262526</td>\n",
       "      <td>5.232015</td>\n",
       "      <td>124.571796</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>180</th>\n",
       "      <td>1986-09-01</td>\n",
       "      <td>81.043444</td>\n",
       "      <td>161.646944</td>\n",
       "      <td>28.0</td>\n",
       "      <td>15.3</td>\n",
       "      <td>25.2</td>\n",
       "      <td>18.423159</td>\n",
       "      <td>21.862291</td>\n",
       "      <td>11.576482</td>\n",
       "      <td>20.987343</td>\n",
       "      <td>...</td>\n",
       "      <td>18.521800</td>\n",
       "      <td>73.499208</td>\n",
       "      <td>15.350776</td>\n",
       "      <td>60.915777</td>\n",
       "      <td>17.615648</td>\n",
       "      <td>69.903364</td>\n",
       "      <td>20.945293</td>\n",
       "      <td>83.116241</td>\n",
       "      <td>15.709508</td>\n",
       "      <td>62.339317</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149</th>\n",
       "      <td>1983-06-01</td>\n",
       "      <td>84.186481</td>\n",
       "      <td>220.145093</td>\n",
       "      <td>25.0</td>\n",
       "      <td>18.1</td>\n",
       "      <td>28.5</td>\n",
       "      <td>40.975710</td>\n",
       "      <td>53.510204</td>\n",
       "      <td>43.832860</td>\n",
       "      <td>42.328327</td>\n",
       "      <td>...</td>\n",
       "      <td>19.722251</td>\n",
       "      <td>69.200881</td>\n",
       "      <td>26.038329</td>\n",
       "      <td>91.362558</td>\n",
       "      <td>20.825641</td>\n",
       "      <td>73.072423</td>\n",
       "      <td>18.437083</td>\n",
       "      <td>64.691521</td>\n",
       "      <td>16.304652</td>\n",
       "      <td>57.209306</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>202</th>\n",
       "      <td>1988-08-01</td>\n",
       "      <td>76.215699</td>\n",
       "      <td>159.897527</td>\n",
       "      <td>30.0</td>\n",
       "      <td>25.9</td>\n",
       "      <td>38.6</td>\n",
       "      <td>34.844920</td>\n",
       "      <td>46.659203</td>\n",
       "      <td>37.151740</td>\n",
       "      <td>25.968000</td>\n",
       "      <td>...</td>\n",
       "      <td>27.137804</td>\n",
       "      <td>70.305192</td>\n",
       "      <td>47.651677</td>\n",
       "      <td>123.449941</td>\n",
       "      <td>18.758344</td>\n",
       "      <td>48.596745</td>\n",
       "      <td>29.654392</td>\n",
       "      <td>76.824850</td>\n",
       "      <td>26.893476</td>\n",
       "      <td>69.672218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>181</th>\n",
       "      <td>1986-10-01</td>\n",
       "      <td>81.000699</td>\n",
       "      <td>167.565269</td>\n",
       "      <td>28.0</td>\n",
       "      <td>1.2</td>\n",
       "      <td>2.7</td>\n",
       "      <td>15.408603</td>\n",
       "      <td>15.008802</td>\n",
       "      <td>11.575404</td>\n",
       "      <td>23.516968</td>\n",
       "      <td>...</td>\n",
       "      <td>17.462138</td>\n",
       "      <td>646.745868</td>\n",
       "      <td>14.277211</td>\n",
       "      <td>528.785574</td>\n",
       "      <td>16.343427</td>\n",
       "      <td>605.312112</td>\n",
       "      <td>13.626220</td>\n",
       "      <td>504.674824</td>\n",
       "      <td>11.144311</td>\n",
       "      <td>412.752253</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>199</th>\n",
       "      <td>1988-05-01</td>\n",
       "      <td>76.419611</td>\n",
       "      <td>167.494500</td>\n",
       "      <td>30.0</td>\n",
       "      <td>5.4</td>\n",
       "      <td>9.4</td>\n",
       "      <td>7.584541</td>\n",
       "      <td>9.805782</td>\n",
       "      <td>9.454899</td>\n",
       "      <td>8.924415</td>\n",
       "      <td>...</td>\n",
       "      <td>6.185420</td>\n",
       "      <td>65.802338</td>\n",
       "      <td>4.833630</td>\n",
       "      <td>51.421597</td>\n",
       "      <td>4.517264</td>\n",
       "      <td>48.056005</td>\n",
       "      <td>4.390144</td>\n",
       "      <td>46.703655</td>\n",
       "      <td>5.398250</td>\n",
       "      <td>57.428192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>205</th>\n",
       "      <td>1988-11-01</td>\n",
       "      <td>76.882889</td>\n",
       "      <td>166.653333</td>\n",
       "      <td>30.0</td>\n",
       "      <td>3.2</td>\n",
       "      <td>5.9</td>\n",
       "      <td>4.110568</td>\n",
       "      <td>6.392304</td>\n",
       "      <td>8.707509</td>\n",
       "      <td>9.833722</td>\n",
       "      <td>...</td>\n",
       "      <td>5.790697</td>\n",
       "      <td>98.147403</td>\n",
       "      <td>11.734023</td>\n",
       "      <td>198.881739</td>\n",
       "      <td>6.443577</td>\n",
       "      <td>109.213175</td>\n",
       "      <td>5.413684</td>\n",
       "      <td>91.757357</td>\n",
       "      <td>5.300386</td>\n",
       "      <td>89.837049</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>183</th>\n",
       "      <td>1987-08-01</td>\n",
       "      <td>81.521290</td>\n",
       "      <td>109.789247</td>\n",
       "      <td>29.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>26.9</td>\n",
       "      <td>27.495869</td>\n",
       "      <td>34.054672</td>\n",
       "      <td>19.547592</td>\n",
       "      <td>28.869099</td>\n",
       "      <td>...</td>\n",
       "      <td>21.414241</td>\n",
       "      <td>79.606843</td>\n",
       "      <td>25.072192</td>\n",
       "      <td>93.205173</td>\n",
       "      <td>20.853992</td>\n",
       "      <td>77.524135</td>\n",
       "      <td>21.722900</td>\n",
       "      <td>80.754275</td>\n",
       "      <td>19.628465</td>\n",
       "      <td>72.968270</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>206</th>\n",
       "      <td>1988-12-01</td>\n",
       "      <td>77.263602</td>\n",
       "      <td>168.706935</td>\n",
       "      <td>30.0</td>\n",
       "      <td>5.8</td>\n",
       "      <td>10.5</td>\n",
       "      <td>10.535615</td>\n",
       "      <td>16.421942</td>\n",
       "      <td>14.563527</td>\n",
       "      <td>19.623580</td>\n",
       "      <td>...</td>\n",
       "      <td>16.762498</td>\n",
       "      <td>159.642836</td>\n",
       "      <td>22.380228</td>\n",
       "      <td>213.145032</td>\n",
       "      <td>16.713852</td>\n",
       "      <td>159.179541</td>\n",
       "      <td>14.253559</td>\n",
       "      <td>135.748179</td>\n",
       "      <td>20.224118</td>\n",
       "      <td>192.610649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>1983-07-01</td>\n",
       "      <td>78.891559</td>\n",
       "      <td>178.506989</td>\n",
       "      <td>26.0</td>\n",
       "      <td>15.1</td>\n",
       "      <td>21.0</td>\n",
       "      <td>29.045374</td>\n",
       "      <td>47.967136</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>20.785813</td>\n",
       "      <td>98.980064</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>24.151557</td>\n",
       "      <td>115.007412</td>\n",
       "      <td>24.060396</td>\n",
       "      <td>114.573316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>244</th>\n",
       "      <td>1989-12-01</td>\n",
       "      <td>77.513978</td>\n",
       "      <td>224.037097</td>\n",
       "      <td>31.0</td>\n",
       "      <td>4.2</td>\n",
       "      <td>8.6</td>\n",
       "      <td>5.727381</td>\n",
       "      <td>9.276497</td>\n",
       "      <td>6.187864</td>\n",
       "      <td>11.338842</td>\n",
       "      <td>...</td>\n",
       "      <td>9.112445</td>\n",
       "      <td>105.958658</td>\n",
       "      <td>9.509085</td>\n",
       "      <td>110.570756</td>\n",
       "      <td>9.657551</td>\n",
       "      <td>112.297105</td>\n",
       "      <td>8.462546</td>\n",
       "      <td>98.401702</td>\n",
       "      <td>11.424287</td>\n",
       "      <td>132.840541</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>211</th>\n",
       "      <td>1989-05-01</td>\n",
       "      <td>79.250538</td>\n",
       "      <td>172.074194</td>\n",
       "      <td>30.0</td>\n",
       "      <td>15.9</td>\n",
       "      <td>26.7</td>\n",
       "      <td>26.765373</td>\n",
       "      <td>32.722350</td>\n",
       "      <td>27.540560</td>\n",
       "      <td>28.776790</td>\n",
       "      <td>...</td>\n",
       "      <td>21.827960</td>\n",
       "      <td>81.752660</td>\n",
       "      <td>14.079567</td>\n",
       "      <td>52.732459</td>\n",
       "      <td>14.565926</td>\n",
       "      <td>54.554031</td>\n",
       "      <td>16.934203</td>\n",
       "      <td>63.423983</td>\n",
       "      <td>18.014211</td>\n",
       "      <td>67.468956</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>188</th>\n",
       "      <td>1988-01-01</td>\n",
       "      <td>84.183226</td>\n",
       "      <td>105.351022</td>\n",
       "      <td>29.0</td>\n",
       "      <td>22.6</td>\n",
       "      <td>45.1</td>\n",
       "      <td>17.809584</td>\n",
       "      <td>23.201797</td>\n",
       "      <td>16.980366</td>\n",
       "      <td>23.148739</td>\n",
       "      <td>...</td>\n",
       "      <td>27.570072</td>\n",
       "      <td>61.130979</td>\n",
       "      <td>26.063433</td>\n",
       "      <td>57.790317</td>\n",
       "      <td>20.157410</td>\n",
       "      <td>44.694922</td>\n",
       "      <td>24.691135</td>\n",
       "      <td>54.747528</td>\n",
       "      <td>25.066085</td>\n",
       "      <td>55.578902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>121</th>\n",
       "      <td>1980-07-01</td>\n",
       "      <td>88.531167</td>\n",
       "      <td>52.069917</td>\n",
       "      <td>24.0</td>\n",
       "      <td>12.3</td>\n",
       "      <td>16.4</td>\n",
       "      <td>44.798428</td>\n",
       "      <td>58.728878</td>\n",
       "      <td>21.500591</td>\n",
       "      <td>35.426770</td>\n",
       "      <td>...</td>\n",
       "      <td>32.059211</td>\n",
       "      <td>195.482992</td>\n",
       "      <td>17.422919</td>\n",
       "      <td>106.237313</td>\n",
       "      <td>22.044560</td>\n",
       "      <td>134.418050</td>\n",
       "      <td>35.053422</td>\n",
       "      <td>213.740380</td>\n",
       "      <td>29.458504</td>\n",
       "      <td>179.625026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>227</th>\n",
       "      <td>1990-09-01</td>\n",
       "      <td>83.793444</td>\n",
       "      <td>230.597278</td>\n",
       "      <td>30.0</td>\n",
       "      <td>13.1</td>\n",
       "      <td>18.8</td>\n",
       "      <td>22.408384</td>\n",
       "      <td>26.980852</td>\n",
       "      <td>16.211320</td>\n",
       "      <td>30.013370</td>\n",
       "      <td>...</td>\n",
       "      <td>22.528363</td>\n",
       "      <td>119.831718</td>\n",
       "      <td>21.496716</td>\n",
       "      <td>114.344231</td>\n",
       "      <td>25.191610</td>\n",
       "      <td>133.997925</td>\n",
       "      <td>27.028851</td>\n",
       "      <td>143.770485</td>\n",
       "      <td>19.387534</td>\n",
       "      <td>103.125180</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>164</th>\n",
       "      <td>1983-12-01</td>\n",
       "      <td>80.101505</td>\n",
       "      <td>177.609946</td>\n",
       "      <td>26.0</td>\n",
       "      <td>8.7</td>\n",
       "      <td>19.1</td>\n",
       "      <td>17.262520</td>\n",
       "      <td>20.802042</td>\n",
       "      <td>NaN</td>\n",
       "      <td>22.633263</td>\n",
       "      <td>...</td>\n",
       "      <td>27.465217</td>\n",
       "      <td>143.796948</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>19.277268</td>\n",
       "      <td>100.928103</td>\n",
       "      <td>25.511211</td>\n",
       "      <td>133.566548</td>\n",
       "      <td>25.618344</td>\n",
       "      <td>134.127454</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>172</th>\n",
       "      <td>1984-08-01</td>\n",
       "      <td>81.367611</td>\n",
       "      <td>178.609667</td>\n",
       "      <td>26.0</td>\n",
       "      <td>11.9</td>\n",
       "      <td>18.4</td>\n",
       "      <td>26.598333</td>\n",
       "      <td>43.227250</td>\n",
       "      <td>17.492258</td>\n",
       "      <td>25.231560</td>\n",
       "      <td>...</td>\n",
       "      <td>20.715225</td>\n",
       "      <td>112.582744</td>\n",
       "      <td>22.435973</td>\n",
       "      <td>121.934635</td>\n",
       "      <td>18.226366</td>\n",
       "      <td>99.056336</td>\n",
       "      <td>16.735375</td>\n",
       "      <td>90.953122</td>\n",
       "      <td>24.915364</td>\n",
       "      <td>135.409586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>1982-03-01</td>\n",
       "      <td>86.462798</td>\n",
       "      <td>3.931012</td>\n",
       "      <td>22.0</td>\n",
       "      <td>20.2</td>\n",
       "      <td>42.8</td>\n",
       "      <td>19.561863</td>\n",
       "      <td>27.602293</td>\n",
       "      <td>17.125633</td>\n",
       "      <td>29.911938</td>\n",
       "      <td>...</td>\n",
       "      <td>31.867267</td>\n",
       "      <td>74.456232</td>\n",
       "      <td>27.127022</td>\n",
       "      <td>63.380892</td>\n",
       "      <td>27.050630</td>\n",
       "      <td>63.202405</td>\n",
       "      <td>30.114110</td>\n",
       "      <td>70.360069</td>\n",
       "      <td>40.654537</td>\n",
       "      <td>94.987237</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>1980-01-01</td>\n",
       "      <td>85.790000</td>\n",
       "      <td>131.426812</td>\n",
       "      <td>24.0</td>\n",
       "      <td>10.9</td>\n",
       "      <td>22.3</td>\n",
       "      <td>7.675100</td>\n",
       "      <td>8.564002</td>\n",
       "      <td>8.356658</td>\n",
       "      <td>14.749085</td>\n",
       "      <td>...</td>\n",
       "      <td>11.881415</td>\n",
       "      <td>53.279890</td>\n",
       "      <td>12.826767</td>\n",
       "      <td>57.519134</td>\n",
       "      <td>12.843177</td>\n",
       "      <td>57.592721</td>\n",
       "      <td>13.123440</td>\n",
       "      <td>58.849508</td>\n",
       "      <td>9.252128</td>\n",
       "      <td>41.489364</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>155</th>\n",
       "      <td>1983-12-01</td>\n",
       "      <td>85.738413</td>\n",
       "      <td>229.137778</td>\n",
       "      <td>25.0</td>\n",
       "      <td>10.2</td>\n",
       "      <td>19.1</td>\n",
       "      <td>12.904218</td>\n",
       "      <td>16.832619</td>\n",
       "      <td>13.947499</td>\n",
       "      <td>20.594193</td>\n",
       "      <td>...</td>\n",
       "      <td>20.531020</td>\n",
       "      <td>107.492253</td>\n",
       "      <td>21.433559</td>\n",
       "      <td>112.217586</td>\n",
       "      <td>17.540545</td>\n",
       "      <td>91.835315</td>\n",
       "      <td>20.269613</td>\n",
       "      <td>106.123627</td>\n",
       "      <td>20.729879</td>\n",
       "      <td>108.533399</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>192</th>\n",
       "      <td>1988-05-01</td>\n",
       "      <td>85.680000</td>\n",
       "      <td>77.374462</td>\n",
       "      <td>29.0</td>\n",
       "      <td>18.8</td>\n",
       "      <td>28.8</td>\n",
       "      <td>15.570930</td>\n",
       "      <td>23.394901</td>\n",
       "      <td>15.349945</td>\n",
       "      <td>12.775585</td>\n",
       "      <td>...</td>\n",
       "      <td>12.698558</td>\n",
       "      <td>44.092217</td>\n",
       "      <td>7.847356</td>\n",
       "      <td>27.247763</td>\n",
       "      <td>6.466608</td>\n",
       "      <td>22.453501</td>\n",
       "      <td>9.755113</td>\n",
       "      <td>33.871919</td>\n",
       "      <td>12.879292</td>\n",
       "      <td>44.719763</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>143</th>\n",
       "      <td>1982-12-01</td>\n",
       "      <td>84.846364</td>\n",
       "      <td>197.586364</td>\n",
       "      <td>25.0</td>\n",
       "      <td>3.3</td>\n",
       "      <td>7.3</td>\n",
       "      <td>3.756193</td>\n",
       "      <td>3.947436</td>\n",
       "      <td>5.527008</td>\n",
       "      <td>14.900042</td>\n",
       "      <td>...</td>\n",
       "      <td>5.976222</td>\n",
       "      <td>81.866052</td>\n",
       "      <td>8.493526</td>\n",
       "      <td>116.349669</td>\n",
       "      <td>12.690706</td>\n",
       "      <td>173.845294</td>\n",
       "      <td>5.546993</td>\n",
       "      <td>75.986208</td>\n",
       "      <td>4.861387</td>\n",
       "      <td>66.594338</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>225</th>\n",
       "      <td>1990-07-01</td>\n",
       "      <td>84.656183</td>\n",
       "      <td>230.390430</td>\n",
       "      <td>30.0</td>\n",
       "      <td>24.3</td>\n",
       "      <td>33.6</td>\n",
       "      <td>44.882114</td>\n",
       "      <td>72.884830</td>\n",
       "      <td>36.878510</td>\n",
       "      <td>56.654520</td>\n",
       "      <td>...</td>\n",
       "      <td>32.119099</td>\n",
       "      <td>95.592557</td>\n",
       "      <td>29.884355</td>\n",
       "      <td>88.941534</td>\n",
       "      <td>35.253679</td>\n",
       "      <td>104.921663</td>\n",
       "      <td>36.557713</td>\n",
       "      <td>108.802717</td>\n",
       "      <td>36.559154</td>\n",
       "      <td>108.807005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>162</th>\n",
       "      <td>1983-10-01</td>\n",
       "      <td>79.130000</td>\n",
       "      <td>177.090376</td>\n",
       "      <td>26.0</td>\n",
       "      <td>10.5</td>\n",
       "      <td>19.3</td>\n",
       "      <td>14.715822</td>\n",
       "      <td>16.070024</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>16.677029</td>\n",
       "      <td>86.409477</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>10.751803</td>\n",
       "      <td>55.708824</td>\n",
       "      <td>11.932288</td>\n",
       "      <td>61.825324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <td>1986-07-01</td>\n",
       "      <td>81.862204</td>\n",
       "      <td>167.866075</td>\n",
       "      <td>28.0</td>\n",
       "      <td>14.6</td>\n",
       "      <td>14.1</td>\n",
       "      <td>28.816042</td>\n",
       "      <td>39.782460</td>\n",
       "      <td>25.027298</td>\n",
       "      <td>29.368921</td>\n",
       "      <td>...</td>\n",
       "      <td>20.621696</td>\n",
       "      <td>146.253163</td>\n",
       "      <td>20.280772</td>\n",
       "      <td>143.835266</td>\n",
       "      <td>18.275020</td>\n",
       "      <td>129.610074</td>\n",
       "      <td>29.954945</td>\n",
       "      <td>212.446416</td>\n",
       "      <td>19.954949</td>\n",
       "      <td>141.524462</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>177</th>\n",
       "      <td>1986-06-01</td>\n",
       "      <td>81.376140</td>\n",
       "      <td>167.164386</td>\n",
       "      <td>28.0</td>\n",
       "      <td>13.4</td>\n",
       "      <td>20.0</td>\n",
       "      <td>42.453970</td>\n",
       "      <td>52.122597</td>\n",
       "      <td>42.583220</td>\n",
       "      <td>53.535355</td>\n",
       "      <td>...</td>\n",
       "      <td>20.433761</td>\n",
       "      <td>102.168804</td>\n",
       "      <td>25.295997</td>\n",
       "      <td>126.479985</td>\n",
       "      <td>26.339526</td>\n",
       "      <td>131.697629</td>\n",
       "      <td>21.460504</td>\n",
       "      <td>107.302522</td>\n",
       "      <td>15.881846</td>\n",
       "      <td>79.409230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>1989-05-01</td>\n",
       "      <td>77.988172</td>\n",
       "      <td>208.917204</td>\n",
       "      <td>31.0</td>\n",
       "      <td>7.4</td>\n",
       "      <td>11.5</td>\n",
       "      <td>10.242914</td>\n",
       "      <td>18.228794</td>\n",
       "      <td>13.179846</td>\n",
       "      <td>21.925236</td>\n",
       "      <td>...</td>\n",
       "      <td>8.353402</td>\n",
       "      <td>72.638278</td>\n",
       "      <td>6.737936</td>\n",
       "      <td>58.590744</td>\n",
       "      <td>11.097880</td>\n",
       "      <td>96.503307</td>\n",
       "      <td>6.796232</td>\n",
       "      <td>59.097669</td>\n",
       "      <td>10.035262</td>\n",
       "      <td>87.263145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>1982-06-01</td>\n",
       "      <td>83.734744</td>\n",
       "      <td>156.796538</td>\n",
       "      <td>25.0</td>\n",
       "      <td>4.5</td>\n",
       "      <td>8.1</td>\n",
       "      <td>18.439365</td>\n",
       "      <td>30.495476</td>\n",
       "      <td>15.727141</td>\n",
       "      <td>17.956009</td>\n",
       "      <td>...</td>\n",
       "      <td>8.875155</td>\n",
       "      <td>109.569818</td>\n",
       "      <td>9.342499</td>\n",
       "      <td>115.339500</td>\n",
       "      <td>8.834400</td>\n",
       "      <td>109.066672</td>\n",
       "      <td>8.023909</td>\n",
       "      <td>99.060610</td>\n",
       "      <td>9.292025</td>\n",
       "      <td>114.716354</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>242</th>\n",
       "      <td>1989-10-01</td>\n",
       "      <td>78.614516</td>\n",
       "      <td>221.368817</td>\n",
       "      <td>31.0</td>\n",
       "      <td>13.9</td>\n",
       "      <td>27.2</td>\n",
       "      <td>24.316366</td>\n",
       "      <td>48.264614</td>\n",
       "      <td>13.693448</td>\n",
       "      <td>33.424095</td>\n",
       "      <td>...</td>\n",
       "      <td>27.557057</td>\n",
       "      <td>101.312709</td>\n",
       "      <td>16.889626</td>\n",
       "      <td>62.094212</td>\n",
       "      <td>23.228516</td>\n",
       "      <td>85.398954</td>\n",
       "      <td>24.496286</td>\n",
       "      <td>90.059874</td>\n",
       "      <td>35.837361</td>\n",
       "      <td>131.755005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>1984-05-01</td>\n",
       "      <td>80.843710</td>\n",
       "      <td>177.310215</td>\n",
       "      <td>26.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>20.2</td>\n",
       "      <td>17.330990</td>\n",
       "      <td>20.340748</td>\n",
       "      <td>18.203754</td>\n",
       "      <td>25.714876</td>\n",
       "      <td>...</td>\n",
       "      <td>14.133939</td>\n",
       "      <td>69.969997</td>\n",
       "      <td>9.306309</td>\n",
       "      <td>46.070838</td>\n",
       "      <td>13.016080</td>\n",
       "      <td>64.436037</td>\n",
       "      <td>11.860572</td>\n",
       "      <td>58.715702</td>\n",
       "      <td>11.197928</td>\n",
       "      <td>55.435289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>221</th>\n",
       "      <td>1990-03-01</td>\n",
       "      <td>82.240860</td>\n",
       "      <td>209.793548</td>\n",
       "      <td>30.0</td>\n",
       "      <td>17.6</td>\n",
       "      <td>31.0</td>\n",
       "      <td>12.982402</td>\n",
       "      <td>17.368153</td>\n",
       "      <td>13.262994</td>\n",
       "      <td>15.679049</td>\n",
       "      <td>...</td>\n",
       "      <td>21.148992</td>\n",
       "      <td>68.222553</td>\n",
       "      <td>21.008597</td>\n",
       "      <td>67.769668</td>\n",
       "      <td>14.179227</td>\n",
       "      <td>45.739441</td>\n",
       "      <td>23.191099</td>\n",
       "      <td>74.809998</td>\n",
       "      <td>25.580999</td>\n",
       "      <td>82.519351</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>215</th>\n",
       "      <td>1989-09-01</td>\n",
       "      <td>82.264444</td>\n",
       "      <td>189.608333</td>\n",
       "      <td>30.0</td>\n",
       "      <td>25.2</td>\n",
       "      <td>41.1</td>\n",
       "      <td>33.656170</td>\n",
       "      <td>53.885555</td>\n",
       "      <td>32.385696</td>\n",
       "      <td>36.340878</td>\n",
       "      <td>...</td>\n",
       "      <td>33.836372</td>\n",
       "      <td>82.326939</td>\n",
       "      <td>42.944442</td>\n",
       "      <td>104.487694</td>\n",
       "      <td>30.502580</td>\n",
       "      <td>74.215523</td>\n",
       "      <td>41.012664</td>\n",
       "      <td>99.787504</td>\n",
       "      <td>38.720350</td>\n",
       "      <td>94.210097</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>57 rows × 26 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          Date        Lat         Lon    NP    Pg    Pc  ERAI_prectot  \\\n",
       "229 1990-11-01  84.457278  237.647556  30.0   0.5   3.8      3.506223   \n",
       "134 1982-03-01  81.284368  164.895977  25.0   3.9   9.4      5.428150   \n",
       "153 1983-10-01  85.728596  219.265526  25.0  16.6  32.5     22.214882   \n",
       "195 1988-01-01  74.456500  175.716611  30.0   8.3  15.9     19.281849   \n",
       "187 1987-12-01  83.113441  112.734086  29.0   4.7  10.0      5.180763   \n",
       "126 1981-07-01  76.587971  165.737754  25.0  18.1  23.2     46.557137   \n",
       "87  1981-07-01  87.805484  123.403387  22.0  28.0  38.7     43.884410   \n",
       "171 1984-07-01  81.722903  179.310430  26.0  33.0  42.5     53.239445   \n",
       "218 1989-12-01  83.269355  204.633871  30.0   9.9  17.6      6.838073   \n",
       "248 1990-04-01  76.251389  225.536778  31.0   2.2   6.1      8.250469   \n",
       "167 1984-03-01  80.028944  172.488778  26.0   5.6  12.0      6.120499   \n",
       "200 1988-06-01  76.586605  161.910802  30.0   4.5   8.4     29.351267   \n",
       "182 1987-07-01  80.683925  111.693871  29.0  18.7  22.5     21.469885   \n",
       "174 1984-10-01  81.896559  172.872097  26.0  13.2  20.1     20.865042   \n",
       "157 1984-02-01  85.633854  234.618438  25.0  11.3  19.5      6.212657   \n",
       "234 1989-02-01  77.481548  207.048214  31.0  21.3  42.4     32.025032   \n",
       "220 1990-02-01  82.074405  209.070833  30.0  15.7  31.1      7.239990   \n",
       "120 1980-06-01  88.506358  105.537901  24.0   6.7  12.9     27.898235   \n",
       "259 1991-03-01  72.152151  211.378333  31.0   2.2   5.2      4.430024   \n",
       "249 1990-05-01  76.346237  226.064677  31.0   1.8   4.8      8.504047   \n",
       "91  1981-11-01  89.220000  126.638944  22.0   7.6  16.1     10.508002   \n",
       "116 1980-02-01  86.399467  129.356400  24.0  10.1  22.3      6.253841   \n",
       "72  1980-04-01  78.580778  151.989833  22.0   2.0   5.7      2.645907   \n",
       "246 1990-02-01  76.306548  224.693452  31.0   5.9  13.9      4.747919   \n",
       "256 1990-12-01  72.960000  214.974946  31.0  12.3  23.8     15.258500   \n",
       "232 1991-02-01  83.063210  235.833395  30.0   1.2   4.2      2.484306   \n",
       "180 1986-09-01  81.043444  161.646944  28.0  15.3  25.2     18.423159   \n",
       "149 1983-06-01  84.186481  220.145093  25.0  18.1  28.5     40.975710   \n",
       "202 1988-08-01  76.215699  159.897527  30.0  25.9  38.6     34.844920   \n",
       "181 1986-10-01  81.000699  167.565269  28.0   1.2   2.7     15.408603   \n",
       "199 1988-05-01  76.419611  167.494500  30.0   5.4   9.4      7.584541   \n",
       "205 1988-11-01  76.882889  166.653333  30.0   3.2   5.9      4.110568   \n",
       "183 1987-08-01  81.521290  109.789247  29.0  20.0  26.9     27.495869   \n",
       "206 1988-12-01  77.263602  168.706935  30.0   5.8  10.5     10.535615   \n",
       "159 1983-07-01  78.891559  178.506989  26.0  15.1  21.0     29.045374   \n",
       "244 1989-12-01  77.513978  224.037097  31.0   4.2   8.6      5.727381   \n",
       "211 1989-05-01  79.250538  172.074194  30.0  15.9  26.7     26.765373   \n",
       "188 1988-01-01  84.183226  105.351022  29.0  22.6  45.1     17.809584   \n",
       "121 1980-07-01  88.531167   52.069917  24.0  12.3  16.4     44.798428   \n",
       "227 1990-09-01  83.793444  230.597278  30.0  13.1  18.8     22.408384   \n",
       "164 1983-12-01  80.101505  177.609946  26.0   8.7  19.1     17.262520   \n",
       "172 1984-08-01  81.367611  178.609667  26.0  11.9  18.4     26.598333   \n",
       "95  1982-03-01  86.462798    3.931012  22.0  20.2  42.8     19.561863   \n",
       "115 1980-01-01  85.790000  131.426812  24.0  10.9  22.3      7.675100   \n",
       "155 1983-12-01  85.738413  229.137778  25.0  10.2  19.1     12.904218   \n",
       "192 1988-05-01  85.680000   77.374462  29.0  18.8  28.8     15.570930   \n",
       "143 1982-12-01  84.846364  197.586364  25.0   3.3   7.3      3.756193   \n",
       "225 1990-07-01  84.656183  230.390430  30.0  24.3  33.6     44.882114   \n",
       "162 1983-10-01  79.130000  177.090376  26.0  10.5  19.3     14.715822   \n",
       "178 1986-07-01  81.862204  167.866075  28.0  14.6  14.1     28.816042   \n",
       "177 1986-06-01  81.376140  167.164386  28.0  13.4  20.0     42.453970   \n",
       "237 1989-05-01  77.988172  208.917204  31.0   7.4  11.5     10.242914   \n",
       "137 1982-06-01  83.734744  156.796538  25.0   4.5   8.1     18.439365   \n",
       "242 1989-10-01  78.614516  221.368817  31.0  13.9  27.2     24.316366   \n",
       "169 1984-05-01  80.843710  177.310215  26.0  11.0  20.2     17.330990   \n",
       "221 1990-03-01  82.240860  209.793548  30.0  17.6  31.0     12.982402   \n",
       "215 1989-09-01  82.264444  189.608333  30.0  25.2  41.1     33.656170   \n",
       "\n",
       "     CFSR_prectot  MERRA_prectot  MERRA2_prectot      ...        ERAI_corr  \\\n",
       "229      5.752460       4.161959        9.600878      ...         4.939336   \n",
       "134      8.311910       7.141147       12.375418      ...         8.842732   \n",
       "153     25.417803      17.650217       34.470240      ...        25.175504   \n",
       "195     20.696077      22.736380       23.766132      ...        29.849207   \n",
       "187      8.082131       5.089871        6.526690      ...         8.242759   \n",
       "126     55.927620      31.750350       50.764930      ...        33.317800   \n",
       "87      46.174370      22.219398       38.982533      ...        31.405110   \n",
       "171     53.905410      34.504295       50.333122      ...        38.099877   \n",
       "218      6.979196       8.603964       12.784246      ...        10.879592   \n",
       "248     10.761417      12.667414       13.151982      ...        12.806466   \n",
       "167      8.092849       7.564194       13.434068      ...         9.970603   \n",
       "200     28.456990      20.753227       21.182299      ...        14.127225   \n",
       "182     29.468271      16.826164       34.436386      ...        15.364547   \n",
       "174     24.670158      14.383730       27.149641      ...        23.645768   \n",
       "157      6.729545       5.126431       12.353541      ...         9.208445   \n",
       "234     40.694126      18.994719       31.084469      ...        47.467727   \n",
       "220     10.467795       7.634984       10.972231      ...        10.731164   \n",
       "120     34.289886      17.831097       27.192526      ...        13.427858   \n",
       "259      5.285304       6.797879        9.095493      ...         7.216734   \n",
       "249     20.605352      14.453971       16.353298      ...         6.935304   \n",
       "91      12.805978       6.745749       17.167664      ...        14.802979   \n",
       "116      8.977540       5.399393       12.788603      ...         9.269487   \n",
       "72       3.820143       7.373949        7.497791      ...         4.107006   \n",
       "246     10.501060       4.231576        9.049299      ...         7.037398   \n",
       "256     19.664350      14.248206       18.816673      ...        24.276758   \n",
       "232      4.924433       4.206443        7.601359      ...         3.682256   \n",
       "180     21.862291      11.576482       20.987343      ...        18.521800   \n",
       "149     53.510204      43.832860       42.328327      ...        19.722251   \n",
       "202     46.659203      37.151740       25.968000      ...        27.137804   \n",
       "181     15.008802      11.575404       23.516968      ...        17.462138   \n",
       "199      9.805782       9.454899        8.924415      ...         6.185420   \n",
       "205      6.392304       8.707509        9.833722      ...         5.790697   \n",
       "183     34.054672      19.547592       28.869099      ...        21.414241   \n",
       "206     16.421942      14.563527       19.623580      ...        16.762498   \n",
       "159     47.967136            NaN             NaN      ...        20.785813   \n",
       "244      9.276497       6.187864       11.338842      ...         9.112445   \n",
       "211     32.722350      27.540560       28.776790      ...        21.827960   \n",
       "188     23.201797      16.980366       23.148739      ...        27.570072   \n",
       "121     58.728878      21.500591       35.426770      ...        32.059211   \n",
       "227     26.980852      16.211320       30.013370      ...        22.528363   \n",
       "164     20.802042            NaN       22.633263      ...        27.465217   \n",
       "172     43.227250      17.492258       25.231560      ...        20.715225   \n",
       "95      27.602293      17.125633       29.911938      ...        31.867267   \n",
       "115      8.564002       8.356658       14.749085      ...        11.881415   \n",
       "155     16.832619      13.947499       20.594193      ...        20.531020   \n",
       "192     23.394901      15.349945       12.775585      ...        12.698558   \n",
       "143      3.947436       5.527008       14.900042      ...         5.976222   \n",
       "225     72.884830      36.878510       56.654520      ...        32.119099   \n",
       "162     16.070024            NaN             NaN      ...        16.677029   \n",
       "178     39.782460      25.027298       29.368921      ...        20.621696   \n",
       "177     52.122597      42.583220       53.535355      ...        20.433761   \n",
       "237     18.228794      13.179846       21.925236      ...         8.353402   \n",
       "137     30.495476      15.727141       17.956009      ...         8.875155   \n",
       "242     48.264614      13.693448       33.424095      ...        27.557057   \n",
       "169     20.340748      18.203754       25.714876      ...        14.133939   \n",
       "221     17.368153      13.262994       15.679049      ...        21.148992   \n",
       "215     53.885555      32.385696       36.340878      ...        33.836372   \n",
       "\n",
       "     ERAI_corrbias  MERRA_corr  MERRA_corrbias  MERRA2_corr  MERRA2_corrbias  \\\n",
       "229     129.982526    5.608552      147.593485     6.291006       165.552779   \n",
       "134      94.071614   11.311585      120.336008    11.191613       119.059718   \n",
       "153      77.463089   21.769941       66.984434    23.955548        73.709378   \n",
       "195     187.730861   34.898430      219.486981    20.695022       130.157370   \n",
       "187      82.427586    7.821765       78.217649     5.558932        55.589315   \n",
       "126     143.611207   25.728771      110.899876    31.588840       136.158791   \n",
       "87       81.150154   18.005402       46.525586    24.257159        62.679997   \n",
       "171      89.646769   27.960420       65.789223    31.320144        73.694456   \n",
       "218      61.815861   13.221981       75.124893    10.888635        61.867242   \n",
       "248     209.942060   13.760322      225.579052     9.257512       151.762495   \n",
       "167      83.088358   11.981691       99.847426    12.148995       101.241628   \n",
       "200     168.181246   12.328179      146.764038    10.421743       124.068369   \n",
       "182      68.286877   13.635016       60.600070    21.428287        95.236829   \n",
       "174     117.640637   17.741026       88.263810    18.868001        93.870652   \n",
       "157      47.222792    6.743434       34.581712    10.306082        52.851702   \n",
       "234     111.952186   24.986120       58.929527    25.932571        61.161725   \n",
       "220      34.505349   10.043245       32.293393     9.153708        29.433146   \n",
       "120     104.091919   10.592327       82.111059    13.378789       103.711546   \n",
       "259     138.783344   10.767847      207.073988     8.225439       158.181513   \n",
       "249     144.485502    7.389307      153.943892     8.277537       172.448680   \n",
       "91       91.943971    9.090404       56.462134    11.249166        69.870596   \n",
       "116      41.567206    7.102494       31.849747    10.669037        47.843216   \n",
       "72       72.052730    8.010153      140.528995     5.277600        92.589466   \n",
       "246      50.628764    5.566319       40.045460     7.549480        54.312809   \n",
       "256     102.003184   21.895665       91.998591    16.026591        67.338616   \n",
       "232      87.672767    5.533259      131.744256     6.341520       150.988573   \n",
       "180      73.499208   15.350776       60.915777    17.615648        69.903364   \n",
       "149      69.200881   26.038329       91.362558    20.825641        73.072423   \n",
       "202      70.305192   47.651677      123.449941    18.758344        48.596745   \n",
       "181     646.745868   14.277211      528.785574    16.343427       605.312112   \n",
       "199      65.802338    4.833630       51.421597     4.517264        48.056005   \n",
       "205      98.147403   11.734023      198.881739     6.443577       109.213175   \n",
       "183      79.606843   25.072192       93.205173    20.853992        77.524135   \n",
       "206     159.642836   22.380228      213.145032    16.713852       159.179541   \n",
       "159      98.980064         NaN             NaN          NaN              NaN   \n",
       "244     105.958658    9.509085      110.570756     9.657551       112.297105   \n",
       "211      81.752660   14.079567       52.732459    14.565926        54.554031   \n",
       "188      61.130979   26.063433       57.790317    20.157410        44.694922   \n",
       "121     195.482992   17.422919      106.237313    22.044560       134.418050   \n",
       "227     119.831718   21.496716      114.344231    25.191610       133.997925   \n",
       "164     143.796948         NaN             NaN    19.277268       100.928103   \n",
       "172     112.582744   22.435973      121.934635    18.226366        99.056336   \n",
       "95       74.456232   27.127022       63.380892    27.050630        63.202405   \n",
       "115      53.279890   12.826767       57.519134    12.843177        57.592721   \n",
       "155     107.492253   21.433559      112.217586    17.540545        91.835315   \n",
       "192      44.092217    7.847356       27.247763     6.466608        22.453501   \n",
       "143      81.866052    8.493526      116.349669    12.690706       173.845294   \n",
       "225      95.592557   29.884355       88.941534    35.253679       104.921663   \n",
       "162      86.409477         NaN             NaN          NaN              NaN   \n",
       "178     146.253163   20.280772      143.835266    18.275020       129.610074   \n",
       "177     102.168804   25.295997      126.479985    26.339526       131.697629   \n",
       "237      72.638278    6.737936       58.590744    11.097880        96.503307   \n",
       "137     109.569818    9.342499      115.339500     8.834400       109.066672   \n",
       "242     101.312709   16.889626       62.094212    23.228516        85.398954   \n",
       "169      69.969997    9.306309       46.070838    13.016080        64.436037   \n",
       "221      68.222553   21.008597       67.769668    14.179227        45.739441   \n",
       "215      82.326939   42.944442      104.487694    30.502580        74.215523   \n",
       "\n",
       "     JRA55_corr  JRA55_corrbias  CFSR_corr  CFSR_corrbias  \n",
       "229    8.523328      224.298095   4.769838     125.522047  \n",
       "134   10.321974      109.808234  12.242347     130.237737  \n",
       "153   25.998124       79.994227  18.873185      58.071339  \n",
       "195   24.521549      154.223578  22.359028     140.622814  \n",
       "187    8.874286       88.742862   9.953389      99.533887  \n",
       "126   37.814455      162.993341  28.053389     120.919778  \n",
       "87    27.104950       70.038630  23.161142      59.847912  \n",
       "171   34.681468       81.603454  27.039045      63.621282  \n",
       "218    9.143457       51.951460   8.595092      48.835747  \n",
       "248   14.543996      238.426172  11.460344     187.874484  \n",
       "167   12.572517      104.770972  11.919699      99.330828  \n",
       "200    8.798284      104.741479   8.670894     103.224933  \n",
       "182   17.752427       78.899676  14.781334      65.694820  \n",
       "174   17.400220       86.568257  18.318045      91.134552  \n",
       "157    8.872187       45.498395   7.149876      36.666029  \n",
       "234   45.106566      106.383410  43.235901     101.971464  \n",
       "220   10.748734       34.561846  11.121618      35.760831  \n",
       "120   12.211631       94.663805  10.448188      80.993705  \n",
       "259    7.654339      147.198829   7.784557     149.703010  \n",
       "249    7.494069      156.126434  11.343597     236.324946  \n",
       "91    13.425398       83.387567  10.618491      65.953358  \n",
       "116    8.855226       39.709531   9.538281      42.772563  \n",
       "72     3.280588       57.554178   4.068252      71.372834  \n",
       "246    7.066497       50.838109  11.156962      80.265912  \n",
       "256   22.964679       96.490247  24.217242     101.753116  \n",
       "232    7.277026      173.262526   5.232015     124.571796  \n",
       "180   20.945293       83.116241  15.709508      62.339317  \n",
       "149   18.437083       64.691521  16.304652      57.209306  \n",
       "202   29.654392       76.824850  26.893476      69.672218  \n",
       "181   13.626220      504.674824  11.144311     412.752253  \n",
       "199    4.390144       46.703655   5.398250      57.428192  \n",
       "205    5.413684       91.757357   5.300386      89.837049  \n",
       "183   21.722900       80.754275  19.628465      72.968270  \n",
       "206   14.253559      135.748179  20.224118     192.610649  \n",
       "159   24.151557      115.007412  24.060396     114.573316  \n",
       "244    8.462546       98.401702  11.424287     132.840541  \n",
       "211   16.934203       63.423983  18.014211      67.468956  \n",
       "188   24.691135       54.747528  25.066085      55.578902  \n",
       "121   35.053422      213.740380  29.458504     179.625026  \n",
       "227   27.028851      143.770485  19.387534     103.125180  \n",
       "164   25.511211      133.566548  25.618344     134.127454  \n",
       "172   16.735375       90.953122  24.915364     135.409586  \n",
       "95    30.114110       70.360069  40.654537      94.987237  \n",
       "115   13.123440       58.849508   9.252128      41.489364  \n",
       "155   20.269613      106.123627  20.729879     108.533399  \n",
       "192    9.755113       33.871919  12.879292      44.719763  \n",
       "143    5.546993       75.986208   4.861387      66.594338  \n",
       "225   36.557713      108.802717  36.559154     108.807005  \n",
       "162   10.751803       55.708824  11.932288      61.825324  \n",
       "178   29.954945      212.446416  19.954949     141.524462  \n",
       "177   21.460504      107.302522  15.881846      79.409230  \n",
       "237    6.796232       59.097669  10.035262      87.263145  \n",
       "137    8.023909       99.060610   9.292025     114.716354  \n",
       "242   24.496286       90.059874  35.837361     131.755005  \n",
       "169   11.860572       58.715702  11.197928      55.435289  \n",
       "221   23.191099       74.809998  25.580999      82.519351  \n",
       "215   41.012664       99.787504  38.720350      94.210097  \n",
       "\n",
       "[57 rows x 26 columns]"
      ]
     },
     "execution_count": 327,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 292,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6527242295678021"
      ]
     },
     "execution_count": 292,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "correction.loc[1,'ERAI_bias']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 299,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 82.91132662,  89.18566079,  99.01202525, 100.63690839,\n",
       "        87.86666074,  87.8656094 ,  89.19415056, 108.99224894,\n",
       "       102.86127958,  61.20341692,  95.49814911,  95.17865966])"
      ]
     },
     "execution_count": 299,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "junk = []\n",
    "for im in range(1,13):\n",
    "    junk.append((df.loc[df.Date.dt.month == im, 'ERAI_prectot']*100./correction.loc[im,'ERAI_bias']/df.loc[df.Date.dt.month == im, 'Pc']).median())\n",
    "    \n",
    "junk = np.array(junk)\n",
    "junk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 328,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "/* Put everything inside the global mpl namespace */\n",
       "window.mpl = {};\n",
       "\n",
       "\n",
       "mpl.get_websocket_type = function() {\n",
       "    if (typeof(WebSocket) !== 'undefined') {\n",
       "        return WebSocket;\n",
       "    } else if (typeof(MozWebSocket) !== 'undefined') {\n",
       "        return MozWebSocket;\n",
       "    } else {\n",
       "        alert('Your browser does not have WebSocket support.' +\n",
       "              'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
       "              'Firefox 4 and 5 are also supported but you ' +\n",
       "              'have to enable WebSockets in about:config.');\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
       "    this.id = figure_id;\n",
       "\n",
       "    this.ws = websocket;\n",
       "\n",
       "    this.supports_binary = (this.ws.binaryType != undefined);\n",
       "\n",
       "    if (!this.supports_binary) {\n",
       "        var warnings = document.getElementById(\"mpl-warnings\");\n",
       "        if (warnings) {\n",
       "            warnings.style.display = 'block';\n",
       "            warnings.textContent = (\n",
       "                \"This browser does not support binary websocket messages. \" +\n",
       "                    \"Performance may be slow.\");\n",
       "        }\n",
       "    }\n",
       "\n",
       "    this.imageObj = new Image();\n",
       "\n",
       "    this.context = undefined;\n",
       "    this.message = undefined;\n",
       "    this.canvas = undefined;\n",
       "    this.rubberband_canvas = undefined;\n",
       "    this.rubberband_context = undefined;\n",
       "    this.format_dropdown = undefined;\n",
       "\n",
       "    this.image_mode = 'full';\n",
       "\n",
       "    this.root = $('<div/>');\n",
       "    this._root_extra_style(this.root)\n",
       "    this.root.attr('style', 'display: inline-block');\n",
       "\n",
       "    $(parent_element).append(this.root);\n",
       "\n",
       "    this._init_header(this);\n",
       "    this._init_canvas(this);\n",
       "    this._init_toolbar(this);\n",
       "\n",
       "    var fig = this;\n",
       "\n",
       "    this.waiting = false;\n",
       "\n",
       "    this.ws.onopen =  function () {\n",
       "            fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
       "            fig.send_message(\"send_image_mode\", {});\n",
       "            if (mpl.ratio != 1) {\n",
       "                fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n",
       "            }\n",
       "            fig.send_message(\"refresh\", {});\n",
       "        }\n",
       "\n",
       "    this.imageObj.onload = function() {\n",
       "            if (fig.image_mode == 'full') {\n",
       "                // Full images could contain transparency (where diff images\n",
       "                // almost always do), so we need to clear the canvas so that\n",
       "                // there is no ghosting.\n",
       "                fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
       "            }\n",
       "            fig.context.drawImage(fig.imageObj, 0, 0);\n",
       "        };\n",
       "\n",
       "    this.imageObj.onunload = function() {\n",
       "        fig.ws.close();\n",
       "    }\n",
       "\n",
       "    this.ws.onmessage = this._make_on_message_function(this);\n",
       "\n",
       "    this.ondownload = ondownload;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_header = function() {\n",
       "    var titlebar = $(\n",
       "        '<div class=\"ui-dialog-titlebar ui-widget-header ui-corner-all ' +\n",
       "        'ui-helper-clearfix\"/>');\n",
       "    var titletext = $(\n",
       "        '<div class=\"ui-dialog-title\" style=\"width: 100%; ' +\n",
       "        'text-align: center; padding: 3px;\"/>');\n",
       "    titlebar.append(titletext)\n",
       "    this.root.append(titlebar);\n",
       "    this.header = titletext[0];\n",
       "}\n",
       "\n",
       "\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_canvas = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var canvas_div = $('<div/>');\n",
       "\n",
       "    canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
       "\n",
       "    function canvas_keyboard_event(event) {\n",
       "        return fig.key_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    canvas_div.keydown('key_press', canvas_keyboard_event);\n",
       "    canvas_div.keyup('key_release', canvas_keyboard_event);\n",
       "    this.canvas_div = canvas_div\n",
       "    this._canvas_extra_style(canvas_div)\n",
       "    this.root.append(canvas_div);\n",
       "\n",
       "    var canvas = $('<canvas/>');\n",
       "    canvas.addClass('mpl-canvas');\n",
       "    canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
       "\n",
       "    this.canvas = canvas[0];\n",
       "    this.context = canvas[0].getContext(\"2d\");\n",
       "\n",
       "    var backingStore = this.context.backingStorePixelRatio ||\n",
       "\tthis.context.webkitBackingStorePixelRatio ||\n",
       "\tthis.context.mozBackingStorePixelRatio ||\n",
       "\tthis.context.msBackingStorePixelRatio ||\n",
       "\tthis.context.oBackingStorePixelRatio ||\n",
       "\tthis.context.backingStorePixelRatio || 1;\n",
       "\n",
       "    mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n",
       "\n",
       "    var rubberband = $('<canvas/>');\n",
       "    rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
       "\n",
       "    var pass_mouse_events = true;\n",
       "\n",
       "    canvas_div.resizable({\n",
       "        start: function(event, ui) {\n",
       "            pass_mouse_events = false;\n",
       "        },\n",
       "        resize: function(event, ui) {\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "        stop: function(event, ui) {\n",
       "            pass_mouse_events = true;\n",
       "            fig.request_resize(ui.size.width, ui.size.height);\n",
       "        },\n",
       "    });\n",
       "\n",
       "    function mouse_event_fn(event) {\n",
       "        if (pass_mouse_events)\n",
       "            return fig.mouse_event(event, event['data']);\n",
       "    }\n",
       "\n",
       "    rubberband.mousedown('button_press', mouse_event_fn);\n",
       "    rubberband.mouseup('button_release', mouse_event_fn);\n",
       "    // Throttle sequential mouse events to 1 every 20ms.\n",
       "    rubberband.mousemove('motion_notify', mouse_event_fn);\n",
       "\n",
       "    rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
       "    rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
       "\n",
       "    canvas_div.on(\"wheel\", function (event) {\n",
       "        event = event.originalEvent;\n",
       "        event['data'] = 'scroll'\n",
       "        if (event.deltaY < 0) {\n",
       "            event.step = 1;\n",
       "        } else {\n",
       "            event.step = -1;\n",
       "        }\n",
       "        mouse_event_fn(event);\n",
       "    });\n",
       "\n",
       "    canvas_div.append(canvas);\n",
       "    canvas_div.append(rubberband);\n",
       "\n",
       "    this.rubberband = rubberband;\n",
       "    this.rubberband_canvas = rubberband[0];\n",
       "    this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
       "    this.rubberband_context.strokeStyle = \"#000000\";\n",
       "\n",
       "    this._resize_canvas = function(width, height) {\n",
       "        // Keep the size of the canvas, canvas container, and rubber band\n",
       "        // canvas in synch.\n",
       "        canvas_div.css('width', width)\n",
       "        canvas_div.css('height', height)\n",
       "\n",
       "        canvas.attr('width', width * mpl.ratio);\n",
       "        canvas.attr('height', height * mpl.ratio);\n",
       "        canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n",
       "\n",
       "        rubberband.attr('width', width);\n",
       "        rubberband.attr('height', height);\n",
       "    }\n",
       "\n",
       "    // Set the figure to an initial 600x600px, this will subsequently be updated\n",
       "    // upon first draw.\n",
       "    this._resize_canvas(600, 600);\n",
       "\n",
       "    // Disable right mouse context menu.\n",
       "    $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
       "        return false;\n",
       "    });\n",
       "\n",
       "    function set_focus () {\n",
       "        canvas.focus();\n",
       "        canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    window.setTimeout(set_focus, 100);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items) {\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) {\n",
       "            // put a spacer in here.\n",
       "            continue;\n",
       "        }\n",
       "        var button = $('<button/>');\n",
       "        button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
       "                        'ui-button-icon-only');\n",
       "        button.attr('role', 'button');\n",
       "        button.attr('aria-disabled', 'false');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "\n",
       "        var icon_img = $('<span/>');\n",
       "        icon_img.addClass('ui-button-icon-primary ui-icon');\n",
       "        icon_img.addClass(image);\n",
       "        icon_img.addClass('ui-corner-all');\n",
       "\n",
       "        var tooltip_span = $('<span/>');\n",
       "        tooltip_span.addClass('ui-button-text');\n",
       "        tooltip_span.html(tooltip);\n",
       "\n",
       "        button.append(icon_img);\n",
       "        button.append(tooltip_span);\n",
       "\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    var fmt_picker_span = $('<span/>');\n",
       "\n",
       "    var fmt_picker = $('<select/>');\n",
       "    fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
       "    fmt_picker_span.append(fmt_picker);\n",
       "    nav_element.append(fmt_picker_span);\n",
       "    this.format_dropdown = fmt_picker[0];\n",
       "\n",
       "    for (var ind in mpl.extensions) {\n",
       "        var fmt = mpl.extensions[ind];\n",
       "        var option = $(\n",
       "            '<option/>', {selected: fmt === mpl.default_extension}).html(fmt);\n",
       "        fmt_picker.append(option)\n",
       "    }\n",
       "\n",
       "    // Add hover states to the ui-buttons\n",
       "    $( \".ui-button\" ).hover(\n",
       "        function() { $(this).addClass(\"ui-state-hover\");},\n",
       "        function() { $(this).removeClass(\"ui-state-hover\");}\n",
       "    );\n",
       "\n",
       "    var status_bar = $('<span class=\"mpl-message\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
       "    // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
       "    // which will in turn request a refresh of the image.\n",
       "    this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_message = function(type, properties) {\n",
       "    properties['type'] = type;\n",
       "    properties['figure_id'] = this.id;\n",
       "    this.ws.send(JSON.stringify(properties));\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.send_draw_message = function() {\n",
       "    if (!this.waiting) {\n",
       "        this.waiting = true;\n",
       "        this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
       "    }\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    var format_dropdown = fig.format_dropdown;\n",
       "    var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
       "    fig.ondownload(fig, format);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
       "    var size = msg['size'];\n",
       "    if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
       "        fig._resize_canvas(size[0], size[1]);\n",
       "        fig.send_message(\"refresh\", {});\n",
       "    };\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
       "    var x0 = msg['x0'] / mpl.ratio;\n",
       "    var y0 = (fig.canvas.height - msg['y0']) / mpl.ratio;\n",
       "    var x1 = msg['x1'] / mpl.ratio;\n",
       "    var y1 = (fig.canvas.height - msg['y1']) / mpl.ratio;\n",
       "    x0 = Math.floor(x0) + 0.5;\n",
       "    y0 = Math.floor(y0) + 0.5;\n",
       "    x1 = Math.floor(x1) + 0.5;\n",
       "    y1 = Math.floor(y1) + 0.5;\n",
       "    var min_x = Math.min(x0, x1);\n",
       "    var min_y = Math.min(y0, y1);\n",
       "    var width = Math.abs(x1 - x0);\n",
       "    var height = Math.abs(y1 - y0);\n",
       "\n",
       "    fig.rubberband_context.clearRect(\n",
       "        0, 0, fig.canvas.width, fig.canvas.height);\n",
       "\n",
       "    fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
       "    // Updates the figure title.\n",
       "    fig.header.textContent = msg['label'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
       "    var cursor = msg['cursor'];\n",
       "    switch(cursor)\n",
       "    {\n",
       "    case 0:\n",
       "        cursor = 'pointer';\n",
       "        break;\n",
       "    case 1:\n",
       "        cursor = 'default';\n",
       "        break;\n",
       "    case 2:\n",
       "        cursor = 'crosshair';\n",
       "        break;\n",
       "    case 3:\n",
       "        cursor = 'move';\n",
       "        break;\n",
       "    }\n",
       "    fig.rubberband_canvas.style.cursor = cursor;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
       "    fig.message.textContent = msg['message'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
       "    // Request the server to send over a new figure.\n",
       "    fig.send_draw_message();\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
       "    fig.image_mode = msg['mode'];\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Called whenever the canvas gets updated.\n",
       "    this.send_message(\"ack\", {});\n",
       "}\n",
       "\n",
       "// A function to construct a web socket function for onmessage handling.\n",
       "// Called in the figure constructor.\n",
       "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
       "    return function socket_on_message(evt) {\n",
       "        if (evt.data instanceof Blob) {\n",
       "            /* FIXME: We get \"Resource interpreted as Image but\n",
       "             * transferred with MIME type text/plain:\" errors on\n",
       "             * Chrome.  But how to set the MIME type?  It doesn't seem\n",
       "             * to be part of the websocket stream */\n",
       "            evt.data.type = \"image/png\";\n",
       "\n",
       "            /* Free the memory for the previous frames */\n",
       "            if (fig.imageObj.src) {\n",
       "                (window.URL || window.webkitURL).revokeObjectURL(\n",
       "                    fig.imageObj.src);\n",
       "            }\n",
       "\n",
       "            fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
       "                evt.data);\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "        else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
       "            fig.imageObj.src = evt.data;\n",
       "            fig.updated_canvas_event();\n",
       "            fig.waiting = false;\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        var msg = JSON.parse(evt.data);\n",
       "        var msg_type = msg['type'];\n",
       "\n",
       "        // Call the  \"handle_{type}\" callback, which takes\n",
       "        // the figure and JSON message as its only arguments.\n",
       "        try {\n",
       "            var callback = fig[\"handle_\" + msg_type];\n",
       "        } catch (e) {\n",
       "            console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
       "            return;\n",
       "        }\n",
       "\n",
       "        if (callback) {\n",
       "            try {\n",
       "                // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
       "                callback(fig, msg);\n",
       "            } catch (e) {\n",
       "                console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
       "            }\n",
       "        }\n",
       "    };\n",
       "}\n",
       "\n",
       "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
       "mpl.findpos = function(e) {\n",
       "    //this section is from http://www.quirksmode.org/js/events_properties.html\n",
       "    var targ;\n",
       "    if (!e)\n",
       "        e = window.event;\n",
       "    if (e.target)\n",
       "        targ = e.target;\n",
       "    else if (e.srcElement)\n",
       "        targ = e.srcElement;\n",
       "    if (targ.nodeType == 3) // defeat Safari bug\n",
       "        targ = targ.parentNode;\n",
       "\n",
       "    // jQuery normalizes the pageX and pageY\n",
       "    // pageX,Y are the mouse positions relative to the document\n",
       "    // offset() returns the position of the element relative to the document\n",
       "    var x = e.pageX - $(targ).offset().left;\n",
       "    var y = e.pageY - $(targ).offset().top;\n",
       "\n",
       "    return {\"x\": x, \"y\": y};\n",
       "};\n",
       "\n",
       "/*\n",
       " * return a copy of an object with only non-object keys\n",
       " * we need this to avoid circular references\n",
       " * http://stackoverflow.com/a/24161582/3208463\n",
       " */\n",
       "function simpleKeys (original) {\n",
       "  return Object.keys(original).reduce(function (obj, key) {\n",
       "    if (typeof original[key] !== 'object')\n",
       "        obj[key] = original[key]\n",
       "    return obj;\n",
       "  }, {});\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.mouse_event = function(event, name) {\n",
       "    var canvas_pos = mpl.findpos(event)\n",
       "\n",
       "    if (name === 'button_press')\n",
       "    {\n",
       "        this.canvas.focus();\n",
       "        this.canvas_div.focus();\n",
       "    }\n",
       "\n",
       "    var x = canvas_pos.x * mpl.ratio;\n",
       "    var y = canvas_pos.y * mpl.ratio;\n",
       "\n",
       "    this.send_message(name, {x: x, y: y, button: event.button,\n",
       "                             step: event.step,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "\n",
       "    /* This prevents the web browser from automatically changing to\n",
       "     * the text insertion cursor when the button is pressed.  We want\n",
       "     * to control all of the cursor setting manually through the\n",
       "     * 'cursor' event from matplotlib */\n",
       "    event.preventDefault();\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    // Handle any extra behaviour associated with a key event\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.key_event = function(event, name) {\n",
       "\n",
       "    // Prevent repeat events\n",
       "    if (name == 'key_press')\n",
       "    {\n",
       "        if (event.which === this._key)\n",
       "            return;\n",
       "        else\n",
       "            this._key = event.which;\n",
       "    }\n",
       "    if (name == 'key_release')\n",
       "        this._key = null;\n",
       "\n",
       "    var value = '';\n",
       "    if (event.ctrlKey && event.which != 17)\n",
       "        value += \"ctrl+\";\n",
       "    if (event.altKey && event.which != 18)\n",
       "        value += \"alt+\";\n",
       "    if (event.shiftKey && event.which != 16)\n",
       "        value += \"shift+\";\n",
       "\n",
       "    value += 'k';\n",
       "    value += event.which.toString();\n",
       "\n",
       "    this._key_event_extra(event, name);\n",
       "\n",
       "    this.send_message(name, {key: value,\n",
       "                             guiEvent: simpleKeys(event)});\n",
       "    return false;\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
       "    if (name == 'download') {\n",
       "        this.handle_save(this, null);\n",
       "    } else {\n",
       "        this.send_message(\"toolbar_button\", {name: name});\n",
       "    }\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
       "    this.message.textContent = tooltip;\n",
       "};\n",
       "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to  previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
       "\n",
       "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
       "\n",
       "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
       "    // Create a \"websocket\"-like object which calls the given IPython comm\n",
       "    // object with the appropriate methods. Currently this is a non binary\n",
       "    // socket, so there is still some room for performance tuning.\n",
       "    var ws = {};\n",
       "\n",
       "    ws.close = function() {\n",
       "        comm.close()\n",
       "    };\n",
       "    ws.send = function(m) {\n",
       "        //console.log('sending', m);\n",
       "        comm.send(m);\n",
       "    };\n",
       "    // Register the callback with on_msg.\n",
       "    comm.on_msg(function(msg) {\n",
       "        //console.log('receiving', msg['content']['data'], msg);\n",
       "        // Pass the mpl event to the overriden (by mpl) onmessage function.\n",
       "        ws.onmessage(msg['content']['data'])\n",
       "    });\n",
       "    return ws;\n",
       "}\n",
       "\n",
       "mpl.mpl_figure_comm = function(comm, msg) {\n",
       "    // This is the function which gets called when the mpl process\n",
       "    // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
       "\n",
       "    var id = msg.content.data.id;\n",
       "    // Get hold of the div created by the display call when the Comm\n",
       "    // socket was opened in Python.\n",
       "    var element = $(\"#\" + id);\n",
       "    var ws_proxy = comm_websocket_adapter(comm)\n",
       "\n",
       "    function ondownload(figure, format) {\n",
       "        window.open(figure.imageObj.src);\n",
       "    }\n",
       "\n",
       "    var fig = new mpl.figure(id, ws_proxy,\n",
       "                           ondownload,\n",
       "                           element.get(0));\n",
       "\n",
       "    // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
       "    // web socket which is closed, not our websocket->open comm proxy.\n",
       "    ws_proxy.onopen();\n",
       "\n",
       "    fig.parent_element = element.get(0);\n",
       "    fig.cell_info = mpl.find_output_cell(\"<div id='\" + id + \"'></div>\");\n",
       "    if (!fig.cell_info) {\n",
       "        console.error(\"Failed to find cell for figure\", id, fig);\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    var output_index = fig.cell_info[2]\n",
       "    var cell = fig.cell_info[0];\n",
       "\n",
       "};\n",
       "\n",
       "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
       "    var width = fig.canvas.width/mpl.ratio\n",
       "    fig.root.unbind('remove')\n",
       "\n",
       "    // Update the output cell to use the data from the current canvas.\n",
       "    fig.push_to_output();\n",
       "    var dataURL = fig.canvas.toDataURL();\n",
       "    // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
       "    // the notebook keyboard shortcuts fail.\n",
       "    IPython.keyboard_manager.enable()\n",
       "    $(fig.parent_element).html('<img src=\"' + dataURL + '\" width=\"' + width + '\">');\n",
       "    fig.close_ws(fig, msg);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.close_ws = function(fig, msg){\n",
       "    fig.send_message('closing', msg);\n",
       "    // fig.ws.close()\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
       "    // Turn the data on the canvas into data in the output cell.\n",
       "    var width = this.canvas.width/mpl.ratio\n",
       "    var dataURL = this.canvas.toDataURL();\n",
       "    this.cell_info[1]['text/html'] = '<img src=\"' + dataURL + '\" width=\"' + width + '\">';\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.updated_canvas_event = function() {\n",
       "    // Tell IPython that the notebook contents must change.\n",
       "    IPython.notebook.set_dirty(true);\n",
       "    this.send_message(\"ack\", {});\n",
       "    var fig = this;\n",
       "    // Wait a second, then push the new image to the DOM so\n",
       "    // that it is saved nicely (might be nice to debounce this).\n",
       "    setTimeout(function () { fig.push_to_output() }, 1000);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._init_toolbar = function() {\n",
       "    var fig = this;\n",
       "\n",
       "    var nav_element = $('<div/>')\n",
       "    nav_element.attr('style', 'width: 100%');\n",
       "    this.root.append(nav_element);\n",
       "\n",
       "    // Define a callback function for later on.\n",
       "    function toolbar_event(event) {\n",
       "        return fig.toolbar_button_onclick(event['data']);\n",
       "    }\n",
       "    function toolbar_mouse_event(event) {\n",
       "        return fig.toolbar_button_onmouseover(event['data']);\n",
       "    }\n",
       "\n",
       "    for(var toolbar_ind in mpl.toolbar_items){\n",
       "        var name = mpl.toolbar_items[toolbar_ind][0];\n",
       "        var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
       "        var image = mpl.toolbar_items[toolbar_ind][2];\n",
       "        var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
       "\n",
       "        if (!name) { continue; };\n",
       "\n",
       "        var button = $('<button class=\"btn btn-default\" href=\"#\" title=\"' + name + '\"><i class=\"fa ' + image + ' fa-lg\"></i></button>');\n",
       "        button.click(method_name, toolbar_event);\n",
       "        button.mouseover(tooltip, toolbar_mouse_event);\n",
       "        nav_element.append(button);\n",
       "    }\n",
       "\n",
       "    // Add the status bar.\n",
       "    var status_bar = $('<span class=\"mpl-message\" style=\"text-align:right; float: right;\"/>');\n",
       "    nav_element.append(status_bar);\n",
       "    this.message = status_bar[0];\n",
       "\n",
       "    // Add the close button to the window.\n",
       "    var buttongrp = $('<div class=\"btn-group inline pull-right\"></div>');\n",
       "    var button = $('<button class=\"btn btn-mini btn-primary\" href=\"#\" title=\"Stop Interaction\"><i class=\"fa fa-power-off icon-remove icon-large\"></i></button>');\n",
       "    button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
       "    button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
       "    buttongrp.append(button);\n",
       "    var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
       "    titlebar.prepend(buttongrp);\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._root_extra_style = function(el){\n",
       "    var fig = this\n",
       "    el.on(\"remove\", function(){\n",
       "\tfig.close_ws(fig, {});\n",
       "    });\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._canvas_extra_style = function(el){\n",
       "    // this is important to make the div 'focusable\n",
       "    el.attr('tabindex', 0)\n",
       "    // reach out to IPython and tell the keyboard manager to turn it's self\n",
       "    // off when our div gets focus\n",
       "\n",
       "    // location in version 3\n",
       "    if (IPython.notebook.keyboard_manager) {\n",
       "        IPython.notebook.keyboard_manager.register_events(el);\n",
       "    }\n",
       "    else {\n",
       "        // location in version 2\n",
       "        IPython.keyboard_manager.register_events(el);\n",
       "    }\n",
       "\n",
       "}\n",
       "\n",
       "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
       "    var manager = IPython.notebook.keyboard_manager;\n",
       "    if (!manager)\n",
       "        manager = IPython.keyboard_manager;\n",
       "\n",
       "    // Check for shift+enter\n",
       "    if (event.shiftKey && event.which == 13) {\n",
       "        this.canvas_div.blur();\n",
       "        event.shiftKey = false;\n",
       "        // Send a \"J\" for go to next cell\n",
       "        event.which = 74;\n",
       "        event.keyCode = 74;\n",
       "        manager.command_mode();\n",
       "        manager.handle_keydown(event);\n",
       "    }\n",
       "}\n",
       "\n",
       "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
       "    fig.ondownload(fig, null);\n",
       "}\n",
       "\n",
       "\n",
       "mpl.find_output_cell = function(html_output) {\n",
       "    // Return the cell and output element which can be found *uniquely* in the notebook.\n",
       "    // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
       "    // IPython event is triggered only after the cells have been serialised, which for\n",
       "    // our purposes (turning an active figure into a static one), is too late.\n",
       "    var cells = IPython.notebook.get_cells();\n",
       "    var ncells = cells.length;\n",
       "    for (var i=0; i<ncells; i++) {\n",
       "        var cell = cells[i];\n",
       "        if (cell.cell_type === 'code'){\n",
       "            for (var j=0; j<cell.output_area.outputs.length; j++) {\n",
       "                var data = cell.output_area.outputs[j];\n",
       "                if (data.data) {\n",
       "                    // IPython >= 3 moved mimebundle to data attribute of output\n",
       "                    data = data.data;\n",
       "                }\n",
       "                if (data['text/html'] == html_output) {\n",
       "                    return [cell, data, j];\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    }\n",
       "}\n",
       "\n",
       "// Register the function which deals with the matplotlib target/channel.\n",
       "// The kernel may be null if the page has been refreshed.\n",
       "if (IPython.notebook.kernel != null) {\n",
       "    IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
       "}\n"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<img src=\"\" width=\"999.4166666666666\">"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
      "['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n"
     ]
    }
   ],
   "source": [
    "fig2, ax2 = plt.subplots(figsize=(10,8))\n",
    "\n",
    "column = ['ERAI_corrbias', 'MERRA_corrbias', 'MERRA2_corrbias', 'JRA55_corrbias', 'CFSR_corrbias']\n",
    "labels = [c.replace('_corrbias','') for c in column]\n",
    "\n",
    "for month in range(1,13):\n",
    "    pos = [month+p for p in [-0.3,-0.15,0.,0.15,0.3]]\n",
    "    #x = [df[df['Date'].dt.month == month][c].values for c in column]\n",
    "    x = columns2list(result[result['Date'].dt.month == month], column=column)\n",
    "    bp = ax2.boxplot(x, positions=pos, widths=0.1, labels=None, patch_artist=True)\n",
    "    setBoxColors(bp)\n",
    "    #ax2.plot(month, junk[month-1], 'ko')\n",
    "\n",
    "ax2.set_ylim(-10.,600.)\n",
    "ax2.set_xlim(0,13)\n",
    "\n",
    "# Hide all but left y-axis\n",
    "ax2.spines['top'].set_visible(False)\n",
    "ax2.spines['bottom'].set_visible(False)\n",
    "ax2.spines['right'].set_visible(False)\n",
    "#ax.set_xticks([])\n",
    "\n",
    "# Format left y-axis\n",
    "ax2.set_ylabel('Bias %', fontsize=20)\n",
    "ax2.axhline(100., linestyle='--', color='k')\n",
    "\n",
    "ax2.set_xticks(range(1,13))\n",
    "ax2.set_xticklabels(calendar.month_abbr[1:])\n",
    "\n",
    "ax2.tick_params(axis='both', which='major', labelsize=15)\n",
    "ax2.tick_params(axis='x', length=0)\n",
    "\n",
    "# Create legend\n",
    "handles = [mpatches.Patch(color=reanalysis_color[r], label=r) for r in labels]\n",
    "ax2.legend(handles=handles, fontsize=18, frameon=False)\n",
    "\n",
    "fig2.savefig(os.path.join(r'C:\\Users\\apbarret\\Documents\\Presentations\\AGU2018',\n",
    "                          'yang_trajectory_reanalysis_corrected_bias_ensemble.png'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
